I need a code that when CheckForZero happens for the first time, after 30 seconds happens again and it go on every 30 seconds.
var waitForZeroInterval = setInterval (CheckForZero, 0);
function CheckForZero ()
{
if ( (unsafeWindow.seconds == 0) && (unsafeWindow.milisec == 0) )
{
clearInterval (waitForZeroInterval);
var targButton = document.getElementById ('bottone1799');
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
targButton.dispatchEvent (clickEvent);
}
};
You can simply track state:
var hasRun = false;
function CheckForZero () {
... snip ...
if (!hasRun) {
hasRun = true;
setInterval(CheckForZero, 30000);
}
}
I'd also recommend using setTimeout() rather than setInterval()/clearInterval() (since it doesn't need to be run on a recurring basis).
Edit: I edited the above code to reflect the OP's modified requirements. I've added another version below to simplify, too.
setTimeout(CheckForZero, 0); // OR just call CheckForZero() if you don't need to defer until processing is complete
function CheckForZero() {
... snip ...
setTimeout(CheckForZero, 30000);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With