templates for self-hosting game jams (or any other kind of jam tbh)
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
6const numEntries = 0; // fix this later to be dynamic
7
8// Date formatting stuff. You probably only need to touch locale and time zone.
9const locale = 'en-US';
10const timeZone = 'America/Chicago';
11
12// DON'T EDIT BELOW THIS LINE
13// unless you know what you're doing.
14
15const start = new Date(startDate);
16const end = new Date(endDate);
17const now = Date.now();
18
19const dateElt = document.getElementById('dates');
20
21const daysElt = document.getElementById('days');
22const hoursElt = document.getElementById('hours');
23const minutesElt = document.getElementById('minutes');
24const secondsElt = document.getElementById('seconds');
25
26const list = document.getElementById('list');
27
28const dayMult = 24*60*60;
29const hourMult = 60*60;
30const minuteMult = 60;
31
32const countdownTick = () => {
33 const now = Date.now();
34 let diff;
35 if (now < start.getTime()) {
36 // Jam hasn't started yet
37 diff = (start.getTime() - now) / 1000; // get total # of seconds
38 } else if (now < end.getTime()) {
39 // Jam has started but not ended
40 diff = (end.getTime() - now) / 1000;
41 } else {
42 // Jam has ended
43 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'}`
44 }
45
46 if (diff) {
47 const days = Math.floor(diff / dayMult);
48 diff = diff - (days * dayMult);
49 const hours = Math.floor(diff / hourMult);
50 diff = diff - (hours * hourMult);
51 const minutes = Math.floor(diff / minuteMult);
52 diff = diff - (minutes * minuteMult);
53 const seconds = Math.floor(diff);
54 daysElt.textContent = days;
55 hoursElt.textContent = hours;
56 minutesElt.textContent = minutes;
57 secondsElt.textContent = seconds;
58 }
59}
60
61if (document.querySelector('.clock')) {
62 countdownTick();
63 if (now < end.getTime()) {
64 setInterval(() => {
65 countdownTick();
66 }, 1000);
67 }
68}