0

Something I can use to automatically refresh a web-page (with specified time intervals) that searches the page for a certain text and stops refreshing once its found/not found.

I found this script that I can use with tampermonkey;

$(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();
}
});

-but it doesn't allow me to specify the time time between each refresh (be it 0.5 seconds or 4 minutes).

If there is a way to do this please let me know, I am a noob at scripting and stuff so any help will be greatly appreciated ;;

1

You can use this modified version:

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

  var intervalHandle = setInterval(function () {    
    if($('body:contains("' + LookFor + '")').length > 0) {
      clearInterval(intervalHandle);
      alert("Found: " + LookFor);
    }
  }, interval * 1000);
});

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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