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

9,236

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);
    }
});
Share:
9,236

Related videos on Youtube

TheOneTeam
Author by

TheOneTeam

I am an software engineer.

Updated on September 18, 2022

Comments

  • TheOneTeam
    TheOneTeam over 1 year

    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