[英]When timer reaches 0 click automatically on the button with Greasemonkey
Here is an example of a timer http://www.prezzipazzi.com/prodotto.php?id=1809 and I need a code that when the timer reaches 0 it click automatically on the button1809. 这是一个计时器示例http://www.prezzipazzi.com/prodotto.php?id=1809 ,我需要一个代码,当计时器达到0时,它会自动单击button1809。
I tried this but it does not work: 我试过了,但是不起作用:
var waitForZeroInterval = setInterval (CheckForZero, 0);
var hasRun = false;
function CheckForZero () {
if ( (unsafeWindow.seconds == 0) && (unsafeWindow.milisec == 0) )
{
clearInterval (waitForZeroInterval);
var targButton = document.getElementById ('bottone1809');
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
targButton.dispatchEvent (clickEvent);
};
if (!hasRun) {
hasRun = true;
setInterval(CheckForZero, 35000);
};
}
Does it click the button one time and then stop, or not click the button at all? 它是否单击按钮一次然后停止,还是根本不单击按钮?
It looks like the hasRun
logic is wrong. 看来
hasRun
逻辑是错误的。
I can't test at that site since (1) it annoys me greatly, (2) It seems to require a registration -- which I will not do. 我无法在该站点进行测试,因为(1)这使我非常烦恼,(2)它似乎需要注册-我不会这样做。 So, please confirm that it operates like this:
因此, 请确认其运作方式如下:
If all that is true, and the current code clicked the button once, then this should work: 如果所有步骤都正确, 并且当前代码单击了一次按钮,那么这应该起作用:
var waitForZeroInterval = null;
function RestartZeroCheck () {
waitForZeroInterval = setInterval (CheckForZero, 100);
}
function CheckForZero () {
if ( (unsafeWindow.seconds == 0) && (unsafeWindow.milisec == 0) )
{
clearInterval (waitForZeroInterval);
var targButton = document.getElementById ('bottone1809');
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
targButton.dispatchEvent (clickEvent);
//--- After a short pause, start checking for the next timer to zero.
setTimeout (RestartZeroCheck, 333);
};
}
RestartZeroCheck ();
Note that if that works, then examining the page's structure suggests that this: 请注意,如果可行,则检查页面的结构表明:
var targButton = document.getElementById ('bottone1809');
Can be changed to this: 可以更改为:
var targButton = document.querySelector (
"#left-inside div.post-wrapper td center input[id^='bottone']"
);
So that the auction number does not have to be hard-coded. 这样拍卖编号就不必硬编码了。
some more update: 一些更新:
HTML 的HTML
<input type="button" name="button1" id="button1" onclick="do_some();"/>
script 脚本
var waitForZeroInterval = setInterval (function(){}, 0);
var hasRun = false;
function CheckForZero () {
clearInterval (waitForZeroInterval);
jQuery('#button1').click();
}
if (!hasRun) {
hasRun = true;
waitForZeroInterval = setInterval(CheckForZero(), 1000);
}
function do_some(){
alert("thank you");
}
This is working fine.. i have tested. 这工作正常..我已经测试过。 i am getting that alert after 1 sec.
1秒后,我收到了警报。 The button is clicked and then the do_some function is called to display alert.
单击该按钮,然后调用do_some函数以显示警报。 You can check here run code
您可以在这里查看运行代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.