2013-04-23 77 views
1

我正在使用Greasemonkey每隔100秒在頁面上單擊一個按鈕。到目前爲止,我能夠讓JS點擊按鈕,但它並沒有等待100秒。Greasemonkey腳本中的時間間隔不等待

我沒有收到任何錯誤,但setInterval只是沒有等待繼續前進。謝謝!

代碼:

console.log('script start'); 
var int =self.setInterval(function(){clickConfirmButton(e)},100000); 
console.log('script start waiting'); 
function clickConfirmButton(e) { 
var buttons = document.getElementsByTagName('button'); 
var clicked = false; 
for (var index=0; index < buttons.length; index++){ 
    if(buttons[index].textContent == "check"){ 
    buttons[index].click(); 
    clicked = true; 
    break; 
    } 
} 
if(!clicked){ 
    setTimeout("window.location.reload()",300*1000); 
} 
} 
clickConfirmButton(); 

回答

3

你必須在最後調用這個函數:

clickConfirmButton(); 

它完全繞過了100秒計時器。刪除或註釋該行。

+0

工作!謝謝! – AAA 2013-04-23 12:37:10

+0

不客氣! – 2013-04-23 12:41:53