]>
Commit | Line | Data |
---|---|---|
7093e9ba MG |
1 | function update_timer(timer){ |
2 | var start = parseInt(timer.dataset.start); | |
3 | var stop = parseInt(timer.dataset.stop); | |
4 | var value = parseInt(timer.dataset.value); | |
5 | var now = Math.floor(Date.now() / 1000); | |
20777d84 | 6 | |
7093e9ba MG |
7 | var left = stop - now; |
8 | var total = stop - start; | |
9 | if(left < 0) | |
10 | left = 0; | |
20777d84 | 11 | |
7093e9ba MG |
12 | if(value) { |
13 | value = Math.max(value * 3 / 10, value * left / total); | |
14 | timer.innerHTML = Math.floor(value); | |
15 | } else { | |
16 | var hours = left / 60 / 60; | |
17 | hours = hours < 10 ? '0' + hours : hours; | |
18 | var minutes = left / 60 % 60; | |
19 | minutes = minutes < 10 ? '0' + minutes : minutes; | |
20 | var seconds = left % 60; | |
21 | seconds = seconds < 10 ? '0' + seconds : seconds; | |
22 | timer.innerHTML = hours + ':' + minutes + ':' + seconds; | |
20777d84 | 23 | } |
7093e9ba | 24 | } |
20777d84 | 25 | |
8345760a MG |
26 | $(() => $('.timer').each(item => { |
27 | update_timer(item); | |
28 | setInterval(() => update_timer(item), 1000); | |
29 | })); |