Using Javascript, refresh a page every 30 seconds UNLESS a phrase appears

Existing code

I use the following code in ViolentMonkey (or GreaseKit or TamperMonkey) to refresh a page every 30 seconds:

setTimeout(function(){ location.reload(); }, 30*1000);

This has been working fine for many years. But now, I want my code to NOT refresh the page if the following phrase is present: Important shizzle

(The reason I don't want it to refresh under this condition is because then I will no longer be able to see what was written.)

I am completely new to Javascript. I've watched some tutorials on YouTube so I think I know the basics.


Strategy thoughts

  1. Search for the phrase Important shizzle - if it exists then end the script.
  2. Then I'd just have my existing code: setTimeout(function(){ location.reload(); }, 30*1000);

Alas I cannot find an elegant Javascript command to abruptly end the script.

Would this work?

if( !document.body.textContent.includes("Important shizzle")) location.reload();

The problem is that the above doesn't do it every 30 seconds, it just does it once



from Recent Questions - Stack Overflow https://ift.tt/38nlwsg
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation