Search code examples
javascripttampermonkeyuserscripts

How can stop a website (game) from refreshing when inactive


I never did anything in Coding but this game i play refreshes every 3 min when inactive (spectating) i want to stop this or edit its script. It also refreshes when opening the DevTools in Chrome.

it script is external <script src="assets/js/new_main_out1.js?461"></script>

window.lastDeath = Date.now()
window.playing = false

window.interval = setInterval(function() {
    if (!window.playing) {
        if ((Date.now() - window.lastDeath) > 3*60*1000) {
            document.location.href = "https://game.com/landing/"
        }
    }
}, 10*1000)

Solution

  • You could continually reset window.lastDeath to within the last minute:

    setInterval(() => {
      window.lastDeath = Date.now();
    }, 60000);
    

    You could also monkeypatch window.setInterval to detect if the page's function is passed, and if it is, ignore it (and start the interval normally otherwise).