From: b Date: Tue, 2 Jan 2024 23:47:06 +0000 (+0000) Subject: js timer countdown rework & enable on click X-Git-Tag: v1.1.0~10 X-Git-Url: http://bicyclesonthemoon.info/git-projects/?a=commitdiff_plain;h=d358368a284f78f4fae8d709b07c212b40db925f;p=ott%2Fbsta js timer countdown rework & enable on click --- diff --git a/bsta_lib.1.pm b/bsta_lib.1.pm index 017e24b..6207b6a 100644 --- a/bsta_lib.1.pm +++ b/bsta_lib.1.pm @@ -1253,7 +1253,7 @@ sub print_viewer_page { } } if ($show_timer) { - print $fh ' '."\n"; + print $fh ' '."\n"; } print_html_head_end($fh); @@ -1299,11 +1299,13 @@ sub print_viewer_page { print $fh '
'."\n"; if ($show_timer) { - print $fh ' ['.$timer_h.''; - print $fh ':'.$timer_m.''; - print $fh ':'.$timer_s.']
'."\n"; + print $fh ' '; + print $fh '['.$timer_h.''; + print $fh ':'.$timer_m.''; + print $fh ':'.$timer_s.']'; + print $fh '
'."\n"; } - print $fh '>'; + print $fh ' >'; if ($show_command_link) { print $fh ''; } diff --git a/timer.js b/timer.js index 7ca7807..964763f 100644 --- a/timer.js +++ b/timer.js @@ -1,9 +1,9 @@ // timer.js -// 3.07.2017 // // The countdown script. // -// Copyright (C) 2017 Balthasar Szczepański +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0 +// Copyright (C) 2017, 2024 Balthasar Szczepański // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as @@ -17,69 +17,79 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// @license-end + +var enabled = false; window.onload = function () { - var ongh; - var ongm; - var ongs; - var ongvh; - var ongvm; - var ongvs; + var e_h; + var e_m; + var e_s; + var h; + var m; + var s; + var countdown; var timer; - ongh = document.getElementById("ongh"); - ongm = document.getElementById("ongm"); - ongs = document.getElementById("ongs"); + e_h = document.getElementById("ongh"); + e_m = document.getElementById("ongm"); + e_s = document.getElementById("ongs"); + + h = +(e_h.innerHTML); + m = +(e_m.innerHTML); + s = +(e_s.innerHTML); - if(ongh == null || ongm == null || ongs == null) { + timer = document.getElementById("timer"); + timer.onclick = function () { + enabled = !enabled; + } + + if (e_h == null || e_m == null || e_s == null) { // window.alert("NUL"); } else { - timer = setInterval (function() { - ongvh = +(ongh.innerHTML); - ongvm = +(ongm.innerHTML); - ongvs = +(ongs.innerHTML); - - if(isNaN(ongvh) || isNaN(ongvm) || isNaN(ongvs)) { + countdown = setInterval (function() { + if(isNaN(h) || isNaN(m) || isNaN(s)) { // window.alert("NAN"); - clearInterval(timer); + clearInterval(countdown); return; } - if(ongvs == 0) { - ongvs = 59; - if(ongvm == 0) { - ongvm == 59; - if(ongvh ==0) { - ongvm = 0; - ongvs = 0; + if (s > 0) { + s -= 1; + } + else { + s = 59; + if (m > 0) { + m -= 1; + } + else { + m == 59; + if (h > 0) { + h -= 1; } else { - ongvh -= 1; + m = 0; + s = 0; } } - else { - ongvm -= 1; - } - } - else { - ongvs -= 1; } - if(ongvh == 0 && ongvm == 0 && ongvs == 0) { - ongh.innerHTML = "00"; - ongm.innerHTML = "00"; - ongs.innerHTML = "NG"; - // window.alert("ONG"); - clearInterval(timer); - return; - } - else { - ongh.innerHTML = ((ongvh<10)?"0":"")+ongvh; - ongm.innerHTML = ((ongvm<10)?"0":"")+ongvm; - ongs.innerHTML = ((ongvs<10)?"0":"")+ongvs; + if (enabled) { + if (h == 0 && m == 0 && s == 0) { + e_h.innerHTML = "00"; + e_m.innerHTML = "00"; + e_s.innerHTML = "NG"; + // window.alert("ONG"); + clearInterval(countdown); + return; + } + else { + e_h.innerHTML = ((h < 10) ? "0" : "") + h; + e_m.innerHTML = ((m < 10) ? "0" : "") + m; + e_s.innerHTML = ((s < 10) ? "0" : "") + s; + } } - }, 1000); } };