From 58c042375a91356ba065ea7f597e432f64419752 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Tue, 18 Aug 2020 13:44:25 +0200 Subject: [PATCH] make timer configurable --- public/index.html | 1 + public/trivabble.js | 39 ++++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/public/index.html b/public/index.html index 6b8cbfe..0f64a51 100644 --- a/public/index.html +++ b/public/index.html @@ -53,6 +53,7 @@

+

diff --git a/public/trivabble.js b/public/trivabble.js index 460a5ce..78361c2 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -1536,30 +1536,31 @@ if (!Object.prototype.hasOwnProperty.call(localStorage, "timerEnable")) { localStorage.timerEnable = Conf.ENABLE_TIMER; } - if (localStorage.timerEnable) { - activateTimer(); - } else { - desactivateTimer(); - } - } - - function activateTimer() { - document.getElementById("timer").style.display = "block"; - localStorage.timer = setInterval(function() { - document.getElementById("timer-turn").innerHTML = timerString(++localStorage.timerTurn) - document.getElementById("timer-global").innerHTML = timerString(++localStorage.timerGlobal); - }, 1000); + document.getElementById("enable-timer").onclick = function() { + setTimerState(document.getElementById("enable-timer").checked); + }; + setTimerState (localStorage.timerEnable); } - function desactivateTimer() { - document.getElementById("timer").style.display = "none"; - if (Object.prototype.hasOwnProperty.call(localStorage, "timer")) { - clearInterval(localStorage.timer); - delete(localStorage.timer); + function setTimerState(state) { + if (state) { + document.getElementById("timer").style.display = "block"; + document.getElementById("enable-timer").checked = true; + localStorage.timer = setInterval(function() { + document.getElementById("timer-turn").innerHTML = timerString(++localStorage.timerTurn) + document.getElementById("timer-global").innerHTML = timerString(++localStorage.timerGlobal); + }, 1000); + } else { + document.getElementById("timer").style.display = "none"; + document.getElementById("enable-timer").checked = false; + if (Object.prototype.hasOwnProperty.call(localStorage, "timer")) { + clearInterval(localStorage.timer); + delete(localStorage.timer); + } + localStorage.timerGlobal = localStorage.timerTurn = 0; } } - function repromptName(f) { if (localStorage.trivabblePlayerName && localStorage.trivabblePlayerName.trim()) { f(); -- 2.30.2