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