使用 Greasemonkey 单击由 JavaScript 创建的按钮
我正在编写一个脚本来单击按钮。该按钮是嵌入在网站上的脚本的一部分。嵌入的脚本在这里: http://pastebin.com/jsBiYZxi 我对 Greasemonkey 和 javascript 相当陌生将军,我在尝试实现这一目标时遇到了障碍。有人可以给我一些指示或建议吗?
I'm working on a script to click a button. The button is part of a script that is embedded on a website. The embedded script is here: http://pastebin.com/jsBiYZxi I'm fairly new to Greasemonkey and javascripting in general and I'm hitting a road block trying to accomplish this. Can anyone give me some pointers or suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看该代码,页面使用 jQuery,按钮具有
play
类,并且位于 ID 为button
的 div 内的表单内。因此,Greasemonkey 脚本中的
unsafeWindow.$("#button form input.play").click();
将点击它。这回答了所述问题。
您并没有说您还想击败按钮的关联计时器。但是,如果这样做,就会涉及更多的问题,因为计时器是在匿名函数内定义的。
击败计时器还存在道德问题。网站所有者可能正在使用该计时器来阻止用户和机器人的滥用/流失(他免费提供“服务”,甚至似乎没有广告)。因此,帮助击败该网站或使该网站超载是不正确的。
Looking at that code, the page uses jQuery and the button has class
play
and is inside a form that is inside a div with idbutton
.So,
unsafeWindow.$("#button form input.play").click();
in your Greasemonkey script will click it.That answers the question as stated.
You didn't say that you wanted to also defeat the button's associated timer. But, if you do, that is quite a bit more involved since the timer is defined inside an anonymous function.
There are also ethical concerns with defeating the timer. The site owner may be using that timer to stop abuse/drain by users and bots (he's providing the "service" for free and doesn't even seem to have advertising). So helping to defeat or overload the site wouldn't be right.