]> bicyclesonthemoon.info Git - botm/oldlogs/commitdiff
js timer countdown rework & enable on click
authorb <rowerynaksiezycu@gmail.com>
Tue, 2 Jan 2024 23:47:06 +0000 (23:47 +0000)
committerb <rowerynaksiezycu@gmail.com>
Tue, 2 Jan 2024 23:47:06 +0000 (23:47 +0000)
bsta_lib.1.pm
timer.js

index 017e24b116a2a118e29dc02606e436425e8ac5eb..6207b6a2b2cd568df5b1ed278415a2d2372f5af4 100644 (file)
@@ -1253,7 +1253,7 @@ sub print_viewer_page {
                }
        }
        if ($show_timer) {
-               print $fh '  <!-- <script src="'.$_timer_url.'"></script> -->'."\n";
+               print $fh '  <script src="'.$_timer_url.'"></script>'."\n";
        }
        
        print_html_head_end($fh);
@@ -1299,11 +1299,13 @@ sub print_viewer_page {
        print $fh '    <div id="command">'."\n";
        
        if ($show_timer) {
-               print $fh '     [<span id="ongh" class="'.$timer_color_h.'">'.$timer_h.'</span>';
-               print $fh      ':<span id="ongm" class="'.$timer_color_m.'">'.$timer_m.'</span>';
-               print $fh      ':<span id="ongs" class="'.$timer_color_s.'">'.$timer_s.'</span>]<br>'."\n";
+               print $fh '     <span id="timer">';
+               print $fh '[<span id="ongh" class="'.$timer_color_h.'">'.$timer_h.'</span>';
+               print $fh ':<span id="ongm" class="'.$timer_color_m.'">'.$timer_m.'</span>';
+               print $fh ':<span id="ongs" class="'.$timer_color_s.'">'.$timer_s.'</span>]';
+               print $fh '</span><br>'."\n";
        }
-       print $fh '&gt;';
+       print $fh '     &gt;';
        if ($show_command_link) {
                print $fh '<a href="'.($access ? $_viewer_next_url : $_viewer_last_url).'">';
        }
index 7ca7807af81096d66b30c640fcfda4dc361b8ae6..964763fa823610f544a18b7e375442756c27124b 100644 (file)
--- 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
 //
 //    You should have received a copy of the GNU Affero General Public License
 //    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// @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);
        }
 };