]>
iEval git - gruntmaster-page.git/blob - js/90-timers.js
3 function update_timer(timer
){
4 const start
= parseInt(timer
.dataset
.start
);
5 const stop
= parseInt(timer
.dataset
.stop
);
6 const value
= parseInt(timer
.dataset
.value
);
7 const now
= Math
.floor(Date
.now() / 1000) + offset
;
9 const left
= Math
.max(stop
- now
, 0);
10 const total
= stop
- start
;
13 timer
.innerHTML
= Math
.floor(Math
.max(value
* 3 / 10, value
* left
/ total
));
15 let hours
= Math
.floor(left
/ 60 / 60);
16 hours
= hours
< 10 ? '0' + hours
: hours
;
17 let minutes
= Math
.floor(left
/ 60) % 60;
18 minutes
= minutes
< 10 ? '0' + minutes
: minutes
;
19 let seconds
= left
% 60;
20 seconds
= seconds
< 10 ? '0' + seconds
: seconds
;
21 timer
.innerHTML
= hours
+ ':' + minutes
+ ':' + seconds
;
26 $('.timer').each(item
=> {
28 setInterval(() => update_timer(item
), 1000);
30 if($('.timer').length
> 0) {
31 const xhr
= new XMLHttpRequest();
32 xhr
.open('HEAD', '/');
34 const srvtime
= Date
.parse(xhr
.getResponseHeader('Date'));
35 offset
= Math
.ceil((srvtime
- Date
.now()) / 1000);
36 console
.log("Offset from server: " + offset
);
This page took 0.048696 seconds and 4 git commands to generate.