-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.js
50 lines (49 loc) · 1.64 KB
/
countdown.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<script>
function getTimeRemaining(endtime) {
var t = Date.parse(endtime)-Date.parse(new Date());
if (t<0) {
document.getElementById('huntForm').remove();
document.getElementById('clock').style.visibility='hidden';
document.getElementById('timeUp-1').style.visibility='visible';
return false; }
var seconds = Math.floor((t / 1000) % 60);
var minutes = Math.floor((t / 1000 / 60) % 60);
var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
var days = Math.floor(t / (1000 * 60 * 60 * 24));
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
function initializeClock(endtime) {
var minutesSpan = document.getElementById('minutes');
var secondsSpan = document.getElementById('seconds');
function updateClock() {
var t = getTimeRemaining(endtime);
if (t.total <= 30000){
if (document.getElementById('hunt').className === 'bg-red-600'){
document.getElementById('hunt').classList.remove('bg-red-600') ;
document.getElementById('hunt').classList.add('bg-blue-300') ;
}
else{
document.getElementById('hunt').classList.remove('bg-blue-300') ;
document.getElementById('hunt').classList.add('bg-red-600') ;
}
}
if (t) {
minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
} else {
clearInterval(timeinterval);
}
}
updateClock();
var timeinterval = setInterval(updateClock, 1000);
}
var deadline = new Date();
deadline.setHours({{ config('chemhunt.exam_hours') }},{{ config('chemhunt.exam_minutes') }},0);
initializeClock(deadline);
</script>