I have followed this thread and it's excellent: How do I click on this button with Greasemonkey?
But I need a script on Greasemonkey to:
- Start script
- Each 1 minute script reloads page (so, *setTimeout(function(){ location.reload(); }, 60*1000);* )
- IF, after reload, on the page appears the button with text "Eureka", click on button and end script
- IF NOT appears the button with text "Eureka", again reload page, check for button with that specific text, if still not appears reload page etc
Code script to click on button when text appears, and it works without problems:
// ==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);
}
I think I need use conditionals; but I don't know where and how. :(
I tried:
// ==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);
}
}