From dd6189378cbc4c8ad22b95951b103880dd39060d Mon Sep 17 00:00:00 2001 From: sageman_ Date: Sat, 3 Jul 2021 14:30:14 +0200 Subject: Implement auto-reload functionality A constant 5 second reload interval instead of increasing the reload intervals by 5 seconds every time so that the user does not miss any time sensitive posts. This also works with the invalid captcha patch. --- static/js/timer.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 static/js/timer.js (limited to 'static/js') 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 -- cgit v1.2.3