templates for self-hosting game jams (or any other kind of jam tbh)
at main 2.3 kB view raw
1const startContent = document.getElementById('startDate') ? document.getElementById('startDate').textContent : null; 2const startDate = document.getElementById('startDate') ? document.getElementById('startDate').getAttribute('data-raw') : null; 3const endContent = document.getElementById('endDate') ? document.getElementById('endDate').textContent : null; 4const endDate = document.getElementById('endDate') ? document.getElementById('endDate').getAttribute('data-raw') : null; 5 6// Date formatting stuff. You probably only need to touch locale and time zone. 7const locale = 'en-US'; 8const timeZone = 'America/Chicago'; 9 10// DON'T EDIT BELOW THIS LINE 11// unless you know what you're doing. 12 13const start = new Date(startDate); 14const end = new Date(endDate); 15const now = Date.now(); 16 17const dateElt = document.getElementById('dates'); 18 19const daysElt = document.getElementById('days'); 20const hoursElt = document.getElementById('hours'); 21const minutesElt = document.getElementById('minutes'); 22const secondsElt = document.getElementById('seconds'); 23 24const list = document.getElementById('list'); 25 26const dayMult = 24*60*60; 27const hourMult = 60*60; 28const minuteMult = 60; 29 30const countdownTick = () => { 31 const now = Date.now(); 32 let diff; 33 if (now < start.getTime()) { 34 // Jam hasn't started yet 35 diff = (start.getTime() - now) / 1000; // get total # of seconds 36 } else if (now < end.getTime()) { 37 // Jam has started but not ended 38 diff = (end.getTime() - now) / 1000; 39 } else { 40 // Jam has ended 41 dates.innerHTML = `The jam is now over. It ran from <b>${startContent}</b> to <b>${endContent}</b>. <a href="submissions.html">View ${numEntries} ${numEntries !== 1 ? 'entries' : 'entry'}` 42 } 43 44 if (diff) { 45 const days = Math.floor(diff / dayMult); 46 diff = diff - (days * dayMult); 47 const hours = Math.floor(diff / hourMult); 48 diff = diff - (hours * hourMult); 49 const minutes = Math.floor(diff / minuteMult); 50 diff = diff - (minutes * minuteMult); 51 const seconds = Math.floor(diff); 52 daysElt.textContent = days; 53 hoursElt.textContent = hours; 54 minutesElt.textContent = minutes; 55 secondsElt.textContent = seconds; 56 } 57} 58 59if (document.querySelector('.clock')) { 60 countdownTick(); 61 if (now < end.getTime()) { 62 setInterval(() => { 63 countdownTick(); 64 }, 1000); 65 } 66}