var exec_interval = 2999; //run every almost-3-seconds (don't make this too low or Chrome ignores you)
var rand_delay_min = 1; //random delay min (added to the exec_interval)
var rand_delay_max = 10000; //random delay max (added to the exec_interval)
var debug = false; // leave off unless you like your JS console filling up with nonsense
// end adjusting things
(debug) && console.log("Tampermonkey script 'Facebook AutoPoke' is running");
function randomInt(min, max) { //min and max inclusive
return Math.floor(Math.random() * (max - min + 1) + min);
}
function multiParentsOf(element, n = 1) {
let {parentNode} = element;
for (let i = 1; parentNode && i < n; ++i) {
({parentNode} = parentNode);
}
(debug) && console.log("Found Poke parent " + parentNode.className);
return parentNode;
}
function tryPoke(){
var pokeclass = "_42ft _4jy0 _4jy3 _4jy1 selected _51sy";
var pokeparentclass = "";
var pokeelements = document.getElementsByClassName(pokeclass);
var pokeparentdepth = 6;
if(pokeelements.length > 1) {
var i;
setTimeout(function(){ //delay the running...
for(i = 1; i < pokeelements.length; ++i) { //find the div items
(debug) && console.log("Looking for Poke buttons...");
if(multiParentsOf(pokeelements[i], pokeparentdepth).className == pokeparentclass) {
(debug) && console.log("Attempting a click...");
pokeelements[i].click();
(debug) && console.log("Poke clicked.");
}
}
}, randomInt(rand_delay_min,rand_delay_max)); //... by this random amount
}
}
setInterval(tryPoke, exec_interval); // run every almost-3-seconds
Facebook changed the Poke page structure - multiParentsOf needs to be depth 6, now.
I also added some console debug messages and some minor code optimization, if you want those in there, as well.
// ==UserScript== // @name Facebook AutoPoke // @version 2.0 // @description Poke your friends autonomously! // @author Zackton & boinger // @match https://www.facebook.com/pokes/?show_outgoing=0 // @match https://www.facebook.com/pokes/?notif_t=poke // @grant none // @start-at document-end // @namespace https://gf.qytechs.cn/users/8935 // ==/UserScript==
var exec_interval = 2999; //run every almost-3-seconds (don't make this too low or Chrome ignores you) var rand_delay_min = 1; //random delay min (added to the exec_interval) var rand_delay_max = 10000; //random delay max (added to the exec_interval)
var debug = false; // leave off unless you like your JS console filling up with nonsense
// end adjusting things
(debug) && console.log("Tampermonkey script 'Facebook AutoPoke' is running");
function randomInt(min, max) { //min and max inclusive return Math.floor(Math.random() * (max - min + 1) + min); }
function multiParentsOf(element, n = 1) { let {parentNode} = element; for (let i = 1; parentNode && i < n; ++i) { ({parentNode} = parentNode); } (debug) && console.log("Found Poke parent " + parentNode.className); return parentNode; }
function tryPoke(){ var pokeclass = "_42ft _4jy0 _4jy3 _4jy1 selected _51sy"; var pokeparentclass = ""; var pokeelements = document.getElementsByClassName(pokeclass); var pokeparentdepth = 6;
}
setInterval(tryPoke, exec_interval); // run every almost-3-seconds