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