Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
How can I check website content on every change?

I have created a (tampermonkey) script to update a website title based on its content:

setInterval(function() {
    var activeSettingsPage = document.querySelector('[class$="dd_sublinks sel"]');
    if (activeSettingsPage != null){
        var activeSettingsPageName = activeSettingsPage.querySelector('.dd_sublinks_linkto').querySelector('.setuplink').querySelector('.setuplink_text').textContent;
        document.title = activeSettingsPageName;
    }

    const DEFAULT_TITLE_ENDING = ' - Zoho CRM';
    if(document.title.includes(' - Zoho CRM')){
        document.title = document.title.replace(DEFAULT_TITLE_ENDING,'');
    }
});

I have used a setInterval() function to run it in an endless loop. Is it a correct solution? Or is there anything better? (From performance, code readability, etc... aspects)

Note: If I will remove setInterval() my tampermonkey script will check the website content only once at the beginning. That is not what I am looking for.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You might also wish to review the various answers in this thread, which additionally covers:

  • // @run-at document-idle
  • using promises
  • Brock Adams' waitForKeyElements() utility

Note that the waitForKeyElements() utility, as originally written, requires jQuery.

Here is an updated/revised fork of the waitForKeyElements() utility that:

  • does not require jQuery
  • avoids the quirks associated with setInterval()
  • optionally takes a function (instead of a string) for querying elements on page
about 4 years ago · Santiago Trujillo Relatório

0

You can use a MutationObserver which lets you know when a node (and a title is a node) has changed.

new MutationObserver(function(mutations) {
    console.log("title changed to: " + document.title);
}).observe(
    document.querySelector('title'),
    { subtree: true, characterData: true, childList: true }
);


setInterval(function() {
document.title = Math.random()
}, 1000)
<title>hello world</title>

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda