diff --git a/web/index.html b/web/index.html index f12c08f..1dd7d8c 100644 --- a/web/index.html +++ b/web/index.html @@ -31,7 +31,11 @@
-

0 person tuned in

+
+

joined HH:MM

+

·

+

0 person tuned in

+
100% @@ -51,7 +55,7 @@
diff --git a/web/script.js b/web/script.js index 93cd3df..4e3973f 100644 --- a/web/script.js +++ b/web/script.js @@ -11,6 +11,7 @@ const heartImg = document.getElementById("heart"); const volumeSlider = document.getElementById("volume-slider"); const currentVolumeLabel = document.getElementById("current-volume-label"); const listenerCountLabel = document.getElementById("listener-count"); +const timerDisplayLabel = document.getElementById("timer-display-label"); const notificationContainer = document.getElementById("notification"); const notificationTitle = document.getElementById("notification-title"); const notificationBody = document.getElementById("notification-body"); @@ -31,6 +32,8 @@ let saveVolumeTimeout = null; let meowCount = 0; let ws = connectToWebSocket(); +const joinedTime = new Date(); + function playAudio() { // add a random query parameter at the end to prevent browser caching currentAudio = new Audio(`./current.mp3?t=${Date.now()}`); @@ -229,6 +232,33 @@ function showNotification(title, content, duration) { }, duration); } +function dateToHumanTime(dateVal, includeSeconds = false) { + // Extract hours, minutes + let hours = dateVal.getHours(); + let minutes = dateVal.getMinutes(); + let seconds = dateVal.getSeconds(); + + // Add leading zeros if the values are less than 10 + hours = hours < 10 ? '0' + hours : hours; + minutes = minutes < 10 ? '0' + minutes : minutes; + seconds = seconds < 10 ? '0' + seconds : seconds; + + // Combine into HH:MM format + if (includeSeconds) { + return `${hours}:${minutes}:${seconds}`; + } + return `${hours}:${minutes}`; +} + +function loadTimerDisplay() { + const now = new Date(); + timerDisplayLabel.innerText = `${dateToHumanTime(now)} | joined ${dateToHumanTime(joinedTime)}`; + + // seconds until next full minutes + // + 1 seconds to ensure non null value + setTimeout(loadTimerDisplay, (61 - now.getSeconds()) * 1000); +} + playBtn.onmousedown = () => { clickAudio.play(); document.addEventListener( @@ -300,3 +330,4 @@ loadMeowCount(); loadInitialVolume(); animateCat(); enableSpaceBarControl(); +loadTimerDisplay(); \ No newline at end of file diff --git a/web/style.css b/web/style.css index b89b41a..6ee9d56 100644 --- a/web/style.css +++ b/web/style.css @@ -115,18 +115,39 @@ a { left: 0; right: 0; z-index: -10; - display: flex; - flex-direction: row; - justify-content: space-between; padding: 2rem; z-index: 0; color: var(--text); } -.status-bar > #listener-count { +@media (min-width: 460px){ + .status-bar{ + display: flex; + flex-direction: row; + justify-content: space-between; + } +} + +.status-bar #listener-stats-container { + padding-right: 0.5rem; +} + +.status-bar #listener-stats-container > * { + display: inline-block; margin: 0; opacity: 0.8; - padding-right: 1rem; + padding-right: 0.5rem; +} + +@media (max-width: 650px) { + .status-bar #listener-stats-container > * { + display: block; + margin-bottom: 0.5rem; + } + + .status-bar #listener-stats-container .status-bar-listener-separator { + display: none; + } } .header {