- Mar 22, 2013
- 9,144
- 10,489
I'm using Firefox. I need for a tampermonkey script to wait until an exact number appears in a span, and then run a command.
This is the code:
I want my script to run only when the number there is 0.
I tried this, and it works, but has an issue:
The problem is that this runs even if the number is 10, 20, 30, etc.
---
I think my answer lies in .filter, but after going through a number of Stackoverflow threads, I can't figure out how to use it.
https://stackoverflow.com/questions/2338439/select-element-based-on-exact-text-contentshttps://stackoverflow.com/questions...containing-a-specific-text-value-using-jquery
Maybe something like this?
I don't care if the solution is jquery or javascript or waitforkeyelements. Whatever works.
This is the code:
HTML:
<span class="time">31</span>
I want my script to run only when the number there is 0.
I tried this, and it works, but has an issue:
Code:
// ==UserScript==
// @name bla
// @include https://site
// @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('0')", clickOnFollowButton);
function clickOnFollowButton (jNode) {
setTimeout(function(){ location.reload(); }, 15*1000);
}
The problem is that this runs even if the number is 10, 20, 30, etc.
---
I think my answer lies in .filter, but after going through a number of Stackoverflow threads, I can't figure out how to use it.
https://stackoverflow.com/questions/2338439/select-element-based-on-exact-text-contentshttps://stackoverflow.com/questions...containing-a-specific-text-value-using-jquery
Maybe something like this?
Code:
$("span").filter(function() { return ($(this).text().indexOf('FIND ME') > -1) }); -- anywhere match
$("span").filter(function() { return ($(this).text() === 'FIND ME') }); -- exact match
I don't care if the solution is jquery or javascript or waitforkeyelements. Whatever works.