From ac68a46c4091e0e505b5c1a06a275fd37219bf60 Mon Sep 17 00:00:00 2001 From: Joey Date: Fri, 27 Sep 2019 09:39:16 +0200 Subject: [PATCH] 10 mins into the future by default Signed-off-by: Joey --- app.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 3f60d5a..7b9c2f2 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,5 @@ // vim: set ts=2 sw=2 et tw=80: + // Real code const URL = 'https://usirooms.maggioni.xyz/schedule.html?name='; @@ -118,7 +119,7 @@ async function buildRoomMarkup(roomTitle) { ROOM_LIST.appendChild(room); } -function setTimePreview(date = NOW) { +function setTimePreview(date) { const timePreview = document.getElementById('timepreviewer'); timePreview.innerText = "Time: " + formatTime(date); } @@ -127,11 +128,13 @@ function setupTimeMachine() { const slider = document.getElementById('timemachine'); slider.min = 0; // Remaining minutes until 23:59 - slider.max = 1380 - (NOW.getHours() * 60) - NOW.getMinutes() - 1; + // 24 * 60 - [current hours * 60] - [current minutes] - [1 min to midnight] + slider.max = 1440 - (NOW.getHours() * 60) - NOW.getMinutes() - 1; slider.addEventListener("input", (e) => { - const hours = Math.round(slider.value / 60); + const hours = Math.floor(slider.value / 60); const mins = slider.value % 60; + let newDate = new Date(); newDate.setHours(newDate.getHours() + hours); newDate.setMinutes(newDate.getMinutes() + mins); @@ -143,6 +146,10 @@ function setupTimeMachine() { colorRoom(roomTitle, node, newDate); }); }); + + // 10 mins into the future by default + slider.value = 10; + setTimePreview(new Date(NOW.getTime() + 600000)); } (async function() { @@ -152,4 +159,3 @@ for (const room of ROOMS) { })() setupTimeMachine(); -setTimePreview();