I did do some research on google and the userscripts site but was unsuccessful in finding an answer.
So basically how can I check if specific text is found on a page? And the text is in no special tags or anything.
A crude but fast way, for FF GM:
if (/Text you are looking for/i.test (document.body.innerHTML) )
{
alert ("Found it!");
}
//--- Looking for one of two different texts...
if (/(Text ONE that you are looking for)|(Text TWO that you are looking for)/i.test (document.body.innerHTML) )
{
alert ("Found one!");
}
For more focused searches use jQuery contains
as in this previous question.
for example this script will show if the text specific text
is found on this page.
// ==UserScript==
// @name so5059986
// @namespace test
// @description test
// @include http://stackoverflow.com/questions/5059986/how-to-have-greasemonkey-check-if-text-if-found-on-page
// ==/UserScript==
var xpathResult = document.evaluate("(//text()[contains(., 'specific text')])[1]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
var node=xpathResult.singleNodeValue;
if (node==null)
alert("text not found");
else
alert("text found on page");
I don't know what you mean with special tags. Text is always inside some tags.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With