server/assets/development/scripts/countdown.js
lefuturiste 9002086180 all in one commit: feat: add countdown integration
fix: home nav icon spacing
fix: various typos correction
fix: right email texts
2020-08-03 16:04:22 +00:00

50 lines
No EOL
1.5 KiB
JavaScript

const countdown = document.getElementById('countdown')
const counter = document.getElementById('counter')
const daysContainer = document.getElementById('days')
const hoursContainer = document.getElementById('hours')
const minutesContainer = document.getElementById('minutes')
const secondsContainer = document.getElementById('seconds')
let shown = false
const enableReload = window.location.pathname.indexOf('c') === -1
function render() {
let current = new Date()
let difference = openDate - current
var _second = 1000,
_minute = _second * 60,
_hour = _minute * 60,
_day = _hour * 24
var days = Math.floor(difference / _day),
hours = Math.floor((difference % _day) / _hour),
minutes = Math.floor((difference % _hour) / _minute),
seconds = Math.floor((difference % _minute) / _second)
days = (String(days).length >= 2) ? days : '0' + days
hours = (String(hours).length >= 2) ? hours : '0' + hours
minutes = (String(minutes).length >= 2) ? minutes : '0' + minutes
seconds = (String(seconds).length >= 2) ? seconds : '0' + seconds
if (openDate <= current && enableReload) {
window.location.reload(false)
} else {
daysContainer.textContent = days
hoursContainer.textContent = hours
minutesContainer.textContent = minutes
secondsContainer.textContent = seconds
}
if (!shown) {
setTimeout(() => {
countdown.style.opacity = 1
shown = true
}, 300)
}
}
render()
setInterval(render, 1000)