diff options
author | FChannel0 <77419041+FChannel0@users.noreply.github.com> | 2021-07-03 16:17:15 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-03 16:17:15 -0700 |
commit | a3f45e6a5cb85a43364756bd28a14936d1d95ae7 (patch) | |
tree | 248da60cd32e9b65b96c9e89e2cc3b804d27e63e /static/js/timer.js | |
parent | 875ee4c53d79918ac87d1ce3e208ad27db6c0a90 (diff) | |
parent | 8e3e745c2a8e9f1db6d15a67829b2aa320731c3f (diff) |
Merge pull request #32 from the-sageman/autoreload
Implement auto-reload
Diffstat (limited to 'static/js/timer.js')
-rw-r--r-- | static/js/timer.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/static/js/timer.js b/static/js/timer.js new file mode 100644 index 0000000..8f6516c --- /dev/null +++ b/static/js/timer.js @@ -0,0 +1,38 @@ +var timerCount; +var timerToggle = false; +var timer; +const contentLoadHandler = function(event){ + timerToggle = !!document.getElementById("autoreload-checkbox").checked; + if(timerToggle){ + timerCount = 5; + document.getElementById("autoreload-countdown").innerHTML = "5"; + 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 = 5; + document.getElementById("autoreload-countdown").innerHTML = "5"; + document.getElementById("autoreload-countdown").style.visibility = "visible"; + timer = setInterval(timerFunction, 1000); + }else{ + clearInterval(timer); + document.getElementById("autoreload-countdown").style.visibility = "hidden"; + } +}
\ No newline at end of file |