aboutsummaryrefslogtreecommitdiffstats
path: root/static/modules/music.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/modules/music.js')
-rw-r--r--static/modules/music.js48
1 files changed, 37 insertions, 11 deletions
diff --git a/static/modules/music.js b/static/modules/music.js
index b78a401..5ba3386 100644
--- a/static/modules/music.js
+++ b/static/modules/music.js
@@ -31,9 +31,15 @@ async function post(action, body = {}) {
}
}
-function button(label, action) {
+// Nerd Font glyphs, as on the other tabs.
+const G = { prev: "\uf048", play: "\uf04b", pause: "\uf04c", next: "\uf051",
+ vol: "\uf028", muted: "\uf026" };
+
+function button(glyph, action, label) {
const b = document.createElement("button");
- b.textContent = label;
+ b.className = `nf ${action}`;
+ b.textContent = glyph;
+ b.setAttribute("aria-label", label);
b.onclick = () => post(action);
return b;
}
@@ -57,11 +63,24 @@ export default {
<input type="range" min="0" max="1" step="1" value="0" aria-label="Seek">
<span class="time num">0:00</span>
</div>
- <div class="controls"></div>
+ <div class="controls">
+ <div class="vol">
+ <input type="range" min="0" max="100" step="1" value="0" aria-label="Volume">
+ <span class="level num"></span>
+ </div>
+ </div>
</div>`;
- el.querySelector(".controls").append(
- button("⏮", "prev"), button("⏯", "play"), button("⏭", "next"),
- button("Vol−", "voldown"), button("Mute", "mute"), button("Vol+", "volup"));
+ el.querySelector(".controls").prepend(
+ button(G.prev, "prev", "Previous"), button(G.play, "play", "Play/pause"),
+ button(G.next, "next", "Next"));
+ el.querySelector(".vol").prepend(button(G.vol, "mute", "Mute"));
+ const vol = el.querySelector(".vol input");
+ vol.addEventListener("pointerdown", () => { el._sliding = true; });
+ vol.addEventListener("pointerup", () => { el._sliding = false; });
+ vol.addEventListener("input", () => {
+ el.querySelector(".level").textContent = `${vol.value}%`;
+ post("volume", { level: Number(vol.value) });
+ });
const seek = el.querySelector(".seek input");
seek.addEventListener("pointerdown", () => { el._dragging = true; });
seek.addEventListener("pointerup", () => { el._dragging = false; });
@@ -82,11 +101,18 @@ export default {
el.querySelector(".title").textContent = st.title || "Nothing playing";
el.querySelector(".artist").textContent = st.artist || "";
el.querySelector(".album").textContent = st.album || "";
- el.querySelector(".controls button:nth-child(2)").textContent =
- st.status === "Playing" ? "⏸" : "▶";
- const mute = el.querySelector(".controls button:nth-child(5)");
- mute.classList.toggle("on", Boolean(st.volume?.muted));
- mute.textContent = st.volume?.muted ? "Unmute" : "Mute";
+ el.querySelector("button.play").textContent = st.status === "Playing" ? G.pause : G.play;
+ const muted = Boolean(st.volume?.muted);
+ const mute = el.querySelector("button.mute");
+ mute.classList.toggle("on", muted);
+ mute.textContent = muted ? G.muted : G.vol;
+ mute.setAttribute("aria-label", muted ? "Unmute" : "Mute");
+ const vol = el.querySelector(".vol input");
+ vol.classList.toggle("muted", muted);
+ if (!el._sliding) {
+ vol.value = st.volume?.level ?? 0;
+ el.querySelector(".level").textContent = `${vol.value}%`;
+ }
const seek = el.querySelector(".seek input");
seek.max = Math.max(1, Math.floor(st.length || 0));
if (!el._dragging) seek.value = Math.min(Number(seek.max), Math.floor(st.position || 0));