0

I want to disable an onload javascript countdown timer with userscript or bookmarklet.

function startTimer(duration) {
            var timer = duration, minutes, seconds;
            var refreshIntervalId =  setInterval(function () {
                minutes = parseInt(timer / 60, 10)
                seconds = parseInt(timer % 60, 10);
                minutes = minutes < 10 ?  minutes : minutes;
                seconds = seconds < 10 ?  seconds : seconds;
                // display.text(minutes + ":" + seconds);
                //display.text(seconds);
                $('#timer_msg').html('You can submit request after '+seconds+' seconds');
                if (--timer < 0) {
                    $('#timer_msg').html(' <input type="submit" name="submit_btn" class="btn btn-primary" value="Submit">');                    
                    return;
                }
            }, 1000);
        }
$( document ).ready(function() {

         startTimer(20);


                });

What this timer does is it waits 20 seconds after pageload then shows the submit button, but I want to skip this 20 seconds so that I can submit immediately. I tried re-declaring the function at the bottom of the page with startTimer(0); with userscript but no luck there!

Tried

$('timer_msg').html('<input type="submit" name="submit_btn" class="btn btn-primary" value="Submit">');

but again the timer is ticking.

Then how can I stop this timer with userscript or bookmarklet?

  • Well timers in JS are much like timers in real life explosives unless you know the right wire(ID) it is doomed to "boom" (fire) .But you can try your luck guessing the id but again it's just luck – Vinay Dec 20 '16 at 12:07
  • yeap, but I thought there might be another way of doing this. But there's none I think now. Although I did it by re-declaring the startTimer function at the bottom of the body, it worked. But I don't think it's a good practice to declare a function multiple times. But again it did solve my problem for now. Thanks, Novice! – H.M Rezoan Duranto Dec 20 '16 at 13:29
  • Have you considered re-declare `setInterval` which alwayse call callback after 0ms? – tsh Jan 23 '17 at 07:31
  • With a userscript you could use [this answer](http://stackoverflow.com/a/35937155/145346) to save the interval id and clear it as desired. – Mottie Jan 28 '17 at 02:34
  • Thanks for the heads up @Mottie – H.M Rezoan Duranto Feb 24 '17 at 08:22

0 Answers0