var championships = {} var lastChampionship = null var locations = [] var updateFrequency = 500; // in ms function flattenObjectIntoSingleUniqueArray(object) { return [...new Set(Object.values(object).reduce((arr, t) => arr.concat(Object.values(t)), []))] } function getDateObject() { return new Date() // maybe easier to offset time zone later } function currentDay() { return getDateObject().getDay() } function currentTime() { let date = getDateObject() return date.getHours() * 60 + date.getMinutes() } function nextDay() { let day = currentDay() + 1 if (day > 6) day -= 6 return day } function firstTimeOnDay(day) { return Math.min(...Object.keys(championships[day])) } function firstTimeNextDay() { return firstTimeOnDay(nextDay()) } function nextTime() { let time = currentTime() let nextTimes = Object.keys(championships[currentDay()]).filter((t) => parseInt(t) >= time) if (nextTimes.length < 1) { return null } return Math.min(...nextTimes) } function formatTime(time) { return Math.floor(time/60).toString().padStart(2, '0') + ":" + (time % 60).toString().padStart(2, '0') } function formatSeconds() { return (60 - getDateObject().getSeconds()).toString().padStart(2, '0') } function nextChampionship() { let remainingOffset = 0 let day = currentDay() let time = nextTime() if (time == null) { remainingOffset = 1440 day = nextDay() time = firstTimeNextDay() } return { day: day, time: time, location: championships[day][time], remaining: (remainingOffset + time) - currentTime(), } } function updateChampionshipDetails(next) { document.getElementById('time').innerHTML = formatTime(next.time) document.getElementById('location').innerHTML = next.location } function updateTimer(next) { let remaining = formatTime(next.remaining) + ":" + formatSeconds() document.getElementById('timer').innerHTML = remaining document.title = `${remaining} - ${next.location} - SSO Timer` } function updateChampionshipTable(next) { const weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] let table = `` for (const [day, details] of Object.entries(championships)) { let dayContainer = `