1
Hello, I did a post asking this: Setar Interval every 1 second
And I have the following code:
iniciarVerificacao();
var verificar;
function iniciarVerificacao(){
if(verificar) clearInterval(verificar);
verificar=setInterval(function() {
if ($('#botao').is(':visible')){
console.log('botão vísivel');
clearInterval(verificar);
$('#botao').trigger('click');
console.log('botão removido');
iniciarVerificacao();
}else{
console.log('botão não vísivel');
iniciarVerificacao(); << Aqui seria para reiniciar e verificar novamente se o botão está vísivel (function iniciarVerificacao()
}
}, 1000);
}
What I wanted: That, he checked every 1 second if the button is visible on the page (after an hour (or varies, so the interval of 1 second) the page refreshes and the button appears), and when it appears, it clicks on the button, and an hour of time appears to appear again, and starts the check again. And stay in this infinite cycle, but the interval for when you are removing the button, summarizing:
1->Verifica se o botão está ativo
2->**Para o intervalo para remover o botão**
3->Ativa o intervalo novamente para ver se o botão está ativo (dentro de uma hora)
But I’m having some problems, when the button appears the script gets stopped, I don’t know if it gets stopped because the page updates, or if it stands in the Else, because if you leave the script running forever, it stops in the message: console.log('not visible button');
Does anyone know what it could be?
You are using two different ids:
#botão
and#button
, is that right? They are two separate buttons?– Sam
Add a parameter to the function to specify the time. Ex:
function iniciarVerificacao(ms)
and you can use}, ms);
instead of}, 1000);
. And when to call the functioniniciarVerificacao(1000);
to check every second oriniciarVerificacao(3600000);
for checking every hour.– Valdeir Psr
I edited the post, I put it wrong, both are put. Valdeir, this code checks, but when you refresh the page the script to, or it stops on Else, I don’t know which of the two.
– user92401
I edited the answer.
– Marcelo Shiniti Uchimura