Extension/Script/Program that will refresh page until a certain phrase/keyword is found or is not found?

3

Is there any program/extension that I can use with browser that will refresh a webpage and search for a certain phrase or text and then stop once the phrase is found or is not found.

For example say I made a site that cycles using a randomizer through the words "One," "Two," and "Three."

This program would refresh the page until the word "Three" is found, If I set it to find that word, and then stop once it is found.

OR

This program would refresh the page until the word "Three" is not found, If I set it to find that word, and then stop once it is not found.

I know that we can use curl and grep to do that, but the page is not loaded on webbrowser. This is not what I want. see if there is solution that we can load on browser as well

If there no such things exists, any idea on how to write this kind of program? use what tool to do that?

Thanks

Kit Ho

Posted 2013-03-21T06:56:34.883

Reputation: 3 467

could this method could be expanded for this question important question. https://superuser.com/questions/1320599/custom-chrome-tampermonkey-script-that-reloads-certain-assigned-pages-only-onc

– music2myear – 2018-05-10T22:56:00.530

Answers

3

I made a small script that searches the page, and refreshes the page if it hasn't been found. You'll need to install the Tampermonkey extension and use the following script:

$(document).ready(function() 
{
    var LookFor = "test"; // Change this to find a different string

    if($('body:contains("' + LookFor + '")').length > 0) 
    {
        alert("Found: " + LookFor);
    }
    else
    {
        location.reload();
    }
});

You'll also need to include the jQuery library by pasting it before this script in the Tampermonkey (unless Tampermonkey can do that for you?).

The searching is limited to the body element and it's children, however you can change body to * to search the entire page source, however the script may stop refreshing the page if it finds what you're looking for in the head element for example.


If you want to keep refreshing the page until a specific word isn't found, change the script to the following:
$(document).ready(function() 
{
    var LookFor = "test";

    if($('body:contains("' + LookFor + '")').length > 0) 
    {
        location.reload();
    }
    else
    {
        alert("Didn't find: " + LookFor);
    }
});

Mythrillic

Posted 2013-03-21T06:56:34.883

Reputation: 1 959