How to get greasemonkey Check if text is found on page

I did some research on google and userscripts but couldn't find the answer.

So, how can I check if a specific text is found on a page? And the text does not contain any special tags or anything else.

+4
source share
2 answers

A rough but quick 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 targeted searches, use jQuery contains , as in this previous question .

+4
source

for example, this script will show if specific text 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 do not know what you mean with special tags. The text is always inside some tags.

+3
source

Source: https://habr.com/ru/post/1340550/


All Articles