Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

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|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.