]> bicyclesonthemoon.info Git - ott/bsta/blob - timer.js
bbcode interface reworked; fixed eval_bb
[ott/bsta] / timer.js
1 // timer.js
2 //  3.07.2017
3 // 
4 // The countdown script.
5 //
6 //    Copyright (C) 2017  Balthasar SzczepaƄski
7 //
8 //    This program is free software: you can redistribute it and/or modify
9 //    it under the terms of the GNU Affero General Public License as
10 //    published by the Free Software Foundation, either version 3 of the
11 //    License, or (at your option) any later version.
12 //
13 //    This program is distributed in the hope that it will be useful,
14 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //    GNU Affero General Public License for more details.
17 //
18 //    You should have received a copy of the GNU Affero General Public License
19 //    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21 window.onload = function () {
22         var ongh;
23         var ongm;
24         var ongs;
25         var ongvh;
26         var ongvm;
27         var ongvs;
28         var timer;
29         
30         ongh = document.getElementById("ongh");
31         ongm = document.getElementById("ongm");
32         ongs = document.getElementById("ongs");
33         
34         if(ongh == null || ongm == null || ongs == null) {
35                 // window.alert("NUL");
36         }
37         else {
38                 timer = setInterval (function() {
39                         ongvh = +(ongh.innerHTML);
40                         ongvm = +(ongm.innerHTML);
41                         ongvs = +(ongs.innerHTML);
42                         
43                         if(isNaN(ongvh) || isNaN(ongvm) || isNaN(ongvs)) {
44                                 // window.alert("NAN");
45                                 clearInterval(timer);
46                                 return;
47                         }
48                         
49                         if(ongvs == 0) {
50                                 ongvs = 59;
51                                 if(ongvm == 0) {
52                                         ongvm == 59;
53                                         if(ongvh ==0) {
54                                                 ongvm = 0;
55                                                 ongvs = 0;
56                                         }
57                                         else {
58                                                 ongvh -= 1;
59                                         }
60                                 }
61                                 else {
62                                         ongvm -= 1;
63                                 }
64                         }
65                         else {
66                                 ongvs -= 1;
67                         }
68                         
69                         if(ongvh == 0 && ongvm == 0 && ongvs == 0) {
70                                 ongh.innerHTML = "00";
71                                 ongm.innerHTML = "00";
72                                 ongs.innerHTML = "NG";
73                                 // window.alert("ONG");
74                                 clearInterval(timer);
75                                 return;
76                         }
77                         else {
78                                 ongh.innerHTML = ((ongvh<10)?"0":"")+ongvh;
79                                 ongm.innerHTML = ((ongvm<10)?"0":"")+ongvm;
80                                 ongs.innerHTML = ((ongvs<10)?"0":"")+ongvs;
81                         }
82                         
83                 }, 1000);
84         }
85 };