server/assets/production/scripts/countdown.js

1 line
908 B
JavaScript
Raw Normal View History

const countdown=document.getElementById("countdown"),counter=document.getElementById("counter"),daysContainer=document.getElementById("days"),hoursContainer=document.getElementById("hours"),minutesContainer=document.getElementById("minutes"),secondsContainer=document.getElementById("seconds");let shown=!1;const enableReload=-1===window.location.pathname.indexOf("c");function render(){let e=new Date,n=openDate-e;var t=Math.floor(n/864e5),o=Math.floor(n%864e5/36e5),a=Math.floor(n%36e5/6e4),d=Math.floor(n%6e4/1e3);t=String(t).length>=2?t:"0"+t,o=String(o).length>=2?o:"0"+o,a=String(a).length>=2?a:"0"+a,d=String(d).length>=2?d:"0"+d,openDate<=e&&enableReload?window.location.reload(!1):(daysContainer.textContent=t,hoursContainer.textContent=o,minutesContainer.textContent=a,secondsContainer.textContent=d),shown||setTimeout(()=>{countdown.style.opacity=1,shown=!0},300)}render(),setInterval(render,1e3);