Greasy Fork is available in English.

Discussões » Feedback do Greasy Fork

Convert JS code to script

§
Publicado: 14/01/2016

Convert JS code to script

I have a piece of code and I want it to be executed every 5 seconds on facebook.
I have created a new user script and pasted the javascript code but it do not execute

§
Publicado: 27/02/2016

i got some examples



/////Use setInterval to automatically call the specified function periodically:

var interval = setInterval(function() {
// do ajax request
...............
}, 60 * 1000);
if (some_condition) {
clearInterval(interval); // stop the timer
}

/////Use setTimeout to schedule one run of the function based on condition:////////////////////
var timeout;
(function doAjax() {
// do ajax request
...............
if (some_condition) {
timeout = setTimeout(doAjax, 60 * 1000); // schedule the next run
}
})();
if (another_condition) {
clearTimeout(timeout); // cancel the schedule
}


/////////////////////or the easy way////////

(function(){
// what should be done every 5 seconds
setTimeout(arguments.callee, 5000);
})();


kinda like that

Publicar resposta

Faça o login para publicar uma resposta.