Greasemonkey:如何点击某个按钮

时间:2012-11-24 00:58:18

标签: javascript greasemonkey

我是JavaScript的新手:与Java lol:P非常不同 我想知道我是否有一个按钮,我怎么能连续按下该按钮4-5分钟? 这是页面来源:

<head><title>A>
<link rel="stylesheet" href="i/w/i_style0n.css">
</head>
<body bgcolor=black topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0>
<img src=i/w/sp_.gif height=2><br><table align=center cellspacing=0 cellpadding=2 width=800 style="border:solid 1px yellow;color:white;" bgcolor=#383838><tr><td align=center> &nbsp; <a href=/p/en/forum/read/100/29291/ target=blank>Raffle 12/11/12-25/11/12 </a> {<a href=hef.cfm?&3831&f=hef_detail&hi=29291&ch=100 target=_Blank>UC0</a>} ( <a href=/p/en/forum/read/100/28080/ target=_blank>Details</a> {<a href=hef.cfm?&3831&f=hef_detail&hi=28080&ch=100 target=_Blank>UC0</a>} . <a href=/p/en/forum/read/100/28201/ target=_blank>Winners</a> {<a href=hef.cfm?&3831&f=hef_detail&hi=28201&ch=100 target=_Blank>UC0</a>} ) - <a href=/p/en/forum/read/200/118678/ target=_Blank>Minor updates</a> {<a href=hef.cfm?&8950&f=he_detail&hi=118678&ch=200 target=_Blank>UC0</a>} - <a href=/p/en/forum/read/100/29293/ target=_Blank>Xmas Event </a> {<a href=hef.cfm?&3831&f=hef_detail&hi=29293&ch=100 target=_Blank>UC0</a>} &nbsp; </td></tr></table><img src=i/w/sp_.gif height=5><br><script>idir='i/w/';fdir='i/w/'; loadtop='sc;0;i.cfm;1;12;-999999999999;1149205838665;19979962050;0;Eli';</script><script src="i/w/j_fr_low.js"></script> <script>lowresbar('0;class=res;; class=res><a href=i.cfm?r' + Math.round(Math.random() * 1000000) + '&f=sc_event>;0;');</script><font class=ft>Research > Housing</font><br>&nbsp;<Br><table width=250 class=trane><tr class=tranbox2><td align=center><table border=0><tr><td class=cw>2,304 turns left in research !</td></tr></table></td></tr></table>&nbsp;<br><table cellspacing=0 cellpadding=2 border=0 align=center class=tranbox><tr class=tranbox2><td class=fs> &nbsp; 31 turn(s) used &nbsp; &nbsp; &nbsp;
Credit -188,302,058,116 &nbsp; Food +17,678,556 &nbsp; &nbsp; <font class=cr>Debt - 18,137,549,878</font>
<br><font class=fsr> &nbsp; Bankruptcy warning: Most production has stopped due to debt<br> &nbsp; Reduce your debt as soon as possible !</font></td></tr></table><img src=i/w/sp_.gif height=5><br>&nbsp;<br>
<script src="i/w/j_sc_research2.js"></script>
<script>
function x5n6z3(obj) { if(obj.value == "Start") obj.form.submit(); obj.value = "Wait!"; } function confirmflag() { if (confirm("")) document.location=frf+'?'+ranurl+'f=sc_research2&rtype='+rtype+'&del=1'; else return false; } 

res2('0;1;&kq7e&;Housing;157;2304;0;Start;Wait!;x5n6z3;y61lip;');
</script>
    <br>&nbsp;</td></tr></table></td><td class=fs> <script>ochat('');</script><font color=#747474>08:27 AM &nbsp; 24 Nov 2012<br>46 Player(s) Online<br>  0.05x Load (sec)</td></td></tr></table> <br><br></body></html>

我想每4-5分钟点击“开始”按钮。有人能帮我这个吗?

1 个答案:

答案 0 :(得分:2)

要模拟JavaScript中的点击,您可以执行我在this回答中所说的代码。

function simulateClick(node) {
    var ev = document.createEvent("MouseEvents");
    ev.initMouseEvent("click", true, false, self, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    return node.dispatchEvent(ev);
}

并将其与window.setInterval

结合使用
var nodeToClick = null, // some node
    clicker = function clicker() {
        simulateClick(nodeToClick);
    };
window.setInterval(clicker, 4*60*1000); // 1000ms in sec * 60secs in min * 4 mins