forked from mountain-climber/countdown-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
countdown-lite.min.js
1 lines (1 loc) · 1.55 KB
/
countdown-lite.min.js
1
"use strict";if(document.querySelector(".countdown")){var endtime=document.querySelector(".countdown").getAttribute("data-time");function makeCorrectDate(t){let e=t;return t<10&&(e="0"+t),e}function getDateRemaining(t){var e=Date.parse(t)-Date.now(),o=Math.floor(e/1e3%60),n=Math.floor(e/1e3/60%60),r=Math.floor(e/36e5%24);return{total:e,days:Math.floor(e/864e5),hours:r,minutes:n,seconds:o}}function countdownLite(){let t=document.querySelector(".countdown"),e=t.querySelector(".countdown__days"),o=t.querySelector(".countdown__hours"),n=t.querySelector(".countdown__minutes"),r=t.querySelector(".countdown__seconds");setInterval((function(){let t=getDateRemaining(endtime);switch(Date.now()<=Date.parse(endtime)?(Date.now(),e.textContent=makeCorrectDate(t.days),o.textContent=makeCorrectDate(t.hours),n.textContent=makeCorrectDate(t.minutes),r.textContent=makeCorrectDate(t.seconds)):(e.textContent=0,o.textContent=0,n.textContent=0,r.textContent=0),t.days){case 1:correctHours="Day";break;default:correctHours="Days"}switch(document.querySelector(".countdown__days-text").textContent=correctHours,t.hours){case 1:correctHours="Hour";break;default:correctHours="Hours"}switch(document.querySelector(".countdown__hours-text").textContent=correctHours,t.minutes){case 1:correctMinutes="Minute";break;default:correctMinutes="Minutes"}switch(document.querySelector(".countdown__minutes-text").textContent=correctMinutes,t.seconds){case 1:correctSeconds="Second";break;default:correctSeconds="Seconds"}document.querySelector(".countdown__seconds-text").textContent=correctSeconds}),1e3)}}