diff --git a/web/assets/css/main.css b/web/assets/css/main.css index 430bb91..d5153cb 100644 --- a/web/assets/css/main.css +++ b/web/assets/css/main.css @@ -11,6 +11,7 @@ --secondary-color: #9f2b68; --text-color: #f5f5f5; --text-indent: 1.6rem; + color-scheme: light dark; scrollbar-color: var(--primary-color) var(--background-color); } @media (prefers-color-scheme: light) { @@ -28,6 +29,10 @@ .right { text-align: right; } +.small { font-size: .8rem; } + +.small.player-links a { margin: 0 .2rem; } + a, button { color: var(--primary-color); @@ -64,10 +69,6 @@ h2 { font-size: 1.4rem; margin: 1rem 0; } -small { font-size: .8rem; } - -small.player-links a { margin: 0 .2rem; } - audio { background-color: var(--primary-color); width: 100%; } @@ -105,11 +106,11 @@ header svg text:last-child { font-size: .88rem; } @-moz-document url-prefix() { header svg text:first-child { font-size: 2rem; } } -nav { margin-top: .5rem; } +header nav { margin-top: .5rem; } -nav a { font-variant: small-caps; } +header nav a { font-variant: small-caps; } -nav h1 { +header nav h1 { color: var(--secondary-color); margin: 0; } @@ -147,20 +148,19 @@ input#radio-volume { flex-direction: row; align-items: center; } -#player div:first-child div { - display: flex; - flex-direction: column; -} - #last-songs { margin: 0 auto; min-width: 80%; width: 80%; } -#last-songs tbody tr { +#last-songs :is(thead tr, tbody tr) { display: grid; gap: .5rem; - grid-template-columns: 3rem 2rem 1fr; } + grid-template-columns: 3rem 3rem 1fr; } + +#last-songs thead tr { + font-weight: bold; +} footer { font-size: .8rem; diff --git a/web/assets/js/main.js b/web/assets/js/main.js index c57975f..60026c5 100644 --- a/web/assets/js/main.js +++ b/web/assets/js/main.js @@ -15,23 +15,24 @@ async function updateStatus() { $("radio-duration").textContent = ""; $("radio-listeners").textContent = $("radio-listener-peak").textContent = "0"; - $("last-songs").firstChild.remove(); + $("last-songs").lastChild.remove(); return [-1, null]; } const s = await resp.json(); - if (undefined != s.most_listened_song) { - $("radio-mls-song").textContent = s.most_listened_song.song; - $("radio-mls-listeners").textContent = s.most_listened_song.listeners; - $("radio-mls-date").textContent = (new Intl.DateTimeFormat('en-GB', - {timeStyle: "long", - dateStyle: "long", - timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone})) - .format(new Date(s.most_listened_song.date)) + if (undefined != s.last_songs) { + $("last-songs").lastChild.remove(); + $("last-songs").appendChild(document.createElement("tbody")); + for (let i = 0; i < s.last_songs.length; ++i) { + let row = $("last-songs").lastChild.insertRow(); + row.insertCell().appendChild(document.createTextNode(formatStartAt(new Date(s.last_songs[i].start_at)))); + row.insertCell().appendChild(document.createTextNode((s.last_songs[i].listeners == 0 ? "" : s.last_songs[i].listeners + "/") + (s.last_songs[i].max_listeners == 0 ? "" : s.last_songs[i].max_listeners))); + row.insertCell().appendChild(document.createTextNode(`${s.last_songs[i].artist} - ${s.last_songs[i].title}`)); + } } - if (undefined == s.current_song) + if (undefined == s.current_song || undefined == s.current_song.duration_msec) return [-1, null]; $("radio-song").textContent = `${s.current_song.artist} - ${s.current_song.title}`; @@ -39,17 +40,6 @@ async function updateStatus() { $("radio-listeners").textContent = s.listeners.current; $("radio-listener-peak").textContent = s.listeners.peak; - if (undefined != s.last_songs) { - $("last-songs").firstChild.remove(); - $("last-songs").appendChild(document.createElement("tbody")); - for (let i = 0; i < s.last_songs.length; ++i) { - let row = $("last-songs").insertRow(); - row.insertCell().appendChild(document.createTextNode(formatStartAt(new Date(s.last_songs[i].start_at)))); - row.insertCell().appendChild(document.createTextNode(s.last_songs[i].listeners == 0 ? "" : s.last_songs[i].listeners)); - row.insertCell().appendChild(document.createTextNode(`${s.last_songs[i].artist} - ${s.last_songs[i].title}`)); - } - } - return [s.current_song.duration_msec, new Date(s.current_song.start_at)]; } @@ -94,8 +84,11 @@ audio.hidden = true; const audio_src = audio.childNodes[0].src; const volume = $("radio-volume"); +volume.value = +(localStorage.getItem("volume") || 50) * 100.0; audio.volume = volume.value / 100.0; -volume.addEventListener("input", e => audio.volume = e.target.value / 100.0); +volume.addEventListener("input", e => { + audio.volume = e.target.value / 100.0; + localStorage.setItem("volume", audio.volume); }); $("player").style.display = $("player").firstChild.style.display = "flex"; diff --git a/web/index.templ b/web/index.templ new file mode 100644 index 0000000..2293b8d --- /dev/null +++ b/web/index.templ @@ -0,0 +1,112 @@ +package web + +import "dwelling-radio/internal/radio" +import "strconv" +import "dwelling-radio/pkg/utils" +import "net/http" + +templ Index(curSong *radio.Song, sl []radio.Song, slLen int64, lstnrs *radio.ListenerCounter, r *http.Request) { + + +
+ + + + + + +Now playing: { curSong.Artist } - { curSong.Title } ( { curSong.DurationString() } )
+ } else { +Now playing: ( )
+ } +Current/peak listeners: { strconv.FormatInt(lstnrs.Current(), 10) } / { strconv.FormatInt(lstnrs.Peak(), 10) }
+Notice: information updates every new song. But you can it forcibly.
+Start | +O/M | +Song | +|
{ utils.ToClientTimezone(song.StartAt, r).Format("15:04") } | + if song.MaxListeners != 0 { +{ strconv.FormatInt(song.Listeners, 10) }/{ strconv.FormatInt(song.MaxListeners, 10) } | + } else { ++ } + | { song.Artist } - { song.Title } | +