Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Kill refresh script onclick

I'm trying to write a very simple auto-refreshing userscript that immediately stops refreshing when the page is clicked anywhere. I have absolutely no coding experience so help would be greatly appreciated.

var cancelled = false;
document.body.addEventListener("click",function(){cancelled=true;});
function goodluck() {
if (cancelled=false) {
      setTimeout(function(){ location.reload(); }, Math.floor(Math.random() * 4000));}
else if (cancelled=true) {return;}
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

(function() {
    'use strict';

    var didClick = false;
    var interval = Math.floor(Math.random() * 4000);

    function refresh() {
        var timeout = setTimeout(function() {
            if (didClick) {
                return;
            }
            location.reload();
        }, interval);

        document.addEventListener('click', function clickHandler() {
            if (!didClick) {
                didClick = true;
                clearTimeout(timeout);
            }
            document.removeEventListener('click', clickHandler);
        });
   }

    window.onload = function() {
        refresh();
    };
})();
about 4 years ago · Juan Pablo Isaza Report

0

(function() { 'use strict';

var didClick = false;
var interval = Math.floor(Math.random() * 4000);

function refresh() {
    var timeout = setTimeout(function() {
        if (didClick) {
            return;
        }
        location.reload();
    }, interval);

    document.addEventListener('click', function clickHandler() {
        if (!didClick) {
            didClick = true;
            clearTimeout(timeout);
        }
        document.removeEventListener('click', clickHandler);
    });

}

window.onload = function() {
    refresh();
};

})();

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!