forked from Noso-Project/explorer.nosocoin.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountdown.js
34 lines (31 loc) · 1.03 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
let countdownInterval;
let lastCountdownTime;
function fetchCountdown() {
fetch('https://nosostats.com:49443/api/endOfBlockInUnix')
.then(response => response.text())
.then(data => {
const countdownTime = data.trim() * 1000;
lastCountdownTime = countdownTime;
startCountdown();
})
.catch(error => {
console.error('Error:', error);
});
}
function startCountdown() {
clearInterval(countdownInterval);
countdownInterval = setInterval(() => {
const now = Date.now();
const distance = lastCountdownTime - now;
const minutes = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById('countdown-timer').innerHTML = `${minutes}m ${seconds}s`;
if (distance < 0) {
clearInterval(countdownInterval);
document.getElementById('countdown-timer').innerHTML = 'Block Created';
setTimeout(fetchCountdown, 5000);
setTimeout(startCountdown, 5000);
}
}, 1000);
}
fetchCountdown();