【发布时间】:2017-11-13 14:56:14
【问题描述】:
我关注了这个帖子,非常棒:How do I click on this button with Greasemonkey?
但是我需要一个关于 Greasemonkey 的脚本来:
- 启动脚本
- 每 1 分钟脚本重新加载页面(因此,*setTimeout(function(){ location.reload(); }, 60*1000);* )
- 如果重新加载后,页面上出现带有文本“Eureka”的按钮,请单击按钮并结束脚本
- 如果没有出现带有文本“Eureka”的按钮,再次重新加载页面,检查带有特定文本的按钮,如果仍然没有出现重新加载页面等
文本出现时单击按钮的代码脚本,它可以正常工作:
// ==UserScript==
// @name _Click on a specific link
// @include http://www.mypage.com*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a major design change
introduced in GM 1.0.
It restores the sandbox.
*/
//--- Note that contains() is CASE-SENSITIVE.
waitForKeyElements ("span:contains('Eureka')", clickOnFollowButton);
function clickOnFollowButton (jNode) {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
jNode[0].dispatchEvent (clickEvent);
}
我认为我需要使用条件;但我不知道在哪里以及如何。 :(
我试过了:
// ==UserScript==
// @name _Click on a specific link
// @include http://www.mypage.com*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a major design change
introduced in GM 1.0.
It restores the sandbox.
*/
//--- Note that contains() is CASE-SENSITIVE.
var FREQUENCY = 60*1000;
function clickOnFollowButton (jNode) {
if ("span:contains('Eureka')") {
var clickEvent = document.createEvent ('MouseEvents');
clickEvent.initEvent ('click', true, true);
jNode[0].dispatchEvent (clickEvent);
}
else {
window.setTimeout(window.location.reload, FREQUENCY);
}
}
【问题讨论】:
标签: javascript greasemonkey tampermonkey