Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

96
Vistas
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);

Can I make it stop?

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 unenlightened

I know almost no Javascript. I've watched tutorials on YouTube, to try and learn the basics. I often google small questions and find answers on Stackoverflow (thanks all) - but I'm still very slow


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

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can read the .innerText property of the body, then use String#includes to see if your phrase is present.

If it is present you can return out of the function to end the script.

Something like this:

const timeout = setTimeout(function () {
  if (document.body.innerText.includes('Important shizzle')) return;
  location.reload();
}, 30 * 1000);
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can do it this way :

setInterval(reload, 30*1000);

function reload() {
    if ( isReloadOK() ) location.reload();
}

function isReloadOK(){
    if (document.body.textContent.includes("Important shizzle")) return false;
    return true;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can have the timeout and you can ADD an interval and I will use the example from what you have shown already.. the most important part is clearTimeout

var timeout=setTimeout(function(){ location.reload(); }, 30*1000);
var interval=setInterval(()=>{
  let condition = document.body.textContent.includes("Important shizzle");
  if(condition){clearTimeout(timeout); clearInterval(interval)}
},0);
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda