aboutsummaryrefslogtreecommitdiff
path: root/static/js/timer.js
blob: d8be9de15ec867c69f9b4de126572f35ba8d169e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var timerCount;
var timerToggle = false;
var timer;
const contentLoadHandler = function(event){
    timerToggle = !!document.getElementById("autoreload-checkbox").checked;
    if(timerToggle){
        timerCount = 45;
        document.getElementById("autoreload-countdown").innerHTML = "45";
        document.getElementById("autoreload-countdown").style.visibility = "visible";
        timer = setInterval(timerFunction, 1000);
        document.removeEventListener("DOMContentLoaded", contentLoadHandler, false);
    }
};

document.addEventListener("DOMContentLoaded", contentLoadHandler, false);

function timerFunction(){
    timerCount--;
    document.getElementById("autoreload-countdown").innerHTML = timerCount;
    if(timerCount <= 0){
        document.getElementById("autoreload-countdown").innerHTML = "Refreshing...";
        clearInterval(timer);
        location.reload();
    }
}

function autoTimer(){
    timerToggle = !timerToggle;
    if(timerToggle === true){
        timerCount = 45;
        document.getElementById("autoreload-countdown").innerHTML = "45";
        document.getElementById("autoreload-countdown").style.visibility = "visible";
        timer = setInterval(timerFunction, 1000);
    }else{
        clearInterval(timer);
        document.getElementById("autoreload-countdown").style.visibility = "hidden";
    }
}