web: iOS-style Downloads sections, accent fill on the volume slider

Downloads now groups into Playlists, Albums and Artists card grids plus
Other Songs, with Play/Shuffle up top and a right-click menu per card
(play, queue, remove download). The volume track fills with the accent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-11-20 17:11:41 -08:00
1 parent d30479c6f7
commit 3ecfdaa73b
2 files changed
+53 -30

No files matched your search

+48 -25
View File
@@ -519,7 +519,7 @@ $("#b-mixer").innerHTML = ICON.mixer;
$("#b-lyrics").innerHTML = ICON.lyrics;
$("#b-queue").innerHTML = ICON.queue;
$("#speed").innerHTML = SPEEDS.map(v => `<option value="${v}">${v}×</option>`).join("");
$("#volume").value = S.volume;
$("#volume").value = S.volume; $("#volume").style.setProperty("--v", S.volume * 100 + "%");
const togglePlay = () => { if (Radio.station) return Radio.toggle(); if (!Q.cur()) return; E.playing ? E.pause() : E.play(); saveQueue(); };
$("#b-play").onclick = togglePlay;
@@ -539,7 +539,7 @@ $("#b-mixer").onclick = () => toggleDrawer("mixer");
$("#b-lyrics").onclick = () => toggleDrawer("lyrics");
$("#b-queue").onclick = () => toggleDrawer("queue");
$("#speed").onchange = ev => setSpeed(+ev.target.value);
$("#volume").oninput = ev => { S.volume = +ev.target.value; E.applyGains(); save(); };
$("#volume").oninput = ev => { S.volume = +ev.target.value; ev.target.style.setProperty("--v", S.volume * 100 + "%"); E.applyGains(); save(); };
function applyBar() {
$("#speed").style.display = S.bar.speed ? "" : "none";
for (const k of ["mixer", "lyrics", "queue"]) $(`#b-${k}`).style.display = S.bar[k] ? "" : "none";
@@ -823,15 +823,16 @@ function playFrom(listId, i) {
// A broken image tries its fallback (data-fb) once, then shows the placeholder.
const FB = `onerror="if(this.dataset.fb){this.src=this.dataset.fb;this.dataset.fb=''}else{this.onerror=null;this.src='data:image/gif;base64,R0lGODlhAQABAAAAACw='}"`;
function card({ href, img: src, fb, t, s = "", round, kind, srv, key }) {
function card({ href, img: src, fb, t, s = "", round, kind, srv, key, dl }) {
const nk = kind === "album" || kind === "artist" ? nameKey(t) : "";
const hide = nk && !stemSets()[kind].has(nk);
return `<a class="card ${round ? "round" : ""} ${hide ? "nostem" : ""}" href="${href}" ${kind ? `data-kind="${kind}" data-srv="${esc(srv)}" data-key="${esc(key)}"` : ""} ${nk ? `data-nk="${esc(nk)}"` : ""}>
<div class="art">${src ? `<img loading="lazy" decoding="async" src="${esc(src)}" ${fb ? `data-fb="${esc(fb)}"` : ""} ${FB} alt="">` : `<div class="ph"></div>`}${kind ? `<button class="cplay" data-cardplay title="Play">${ICON.play}</button>` : ""}</div><div class="t">${esc(t)}</div><div class="s">${esc(s)}</div></a>`;
return `<a class="card ${round ? "round" : ""} ${hide ? "nostem" : ""}" href="${href}" ${kind ? `data-kind="${kind}" data-srv="${esc(srv)}" data-key="${esc(key)}"` : ""} ${dl != null ? `data-dl="${dl}"` : ""} ${nk ? `data-nk="${esc(nk)}"` : ""}>
<div class="art">${src ? `<img loading="lazy" decoding="async" src="${esc(src)}" ${fb ? `data-fb="${esc(fb)}"` : ""} ${FB} alt="">` : `<div class="ph"></div>`}${kind || dl != null ? `<button class="cplay" data-cardplay title="Play">${ICON.play}</button>` : ""}</div><div class="t">${esc(t)}</div><div class="s">${esc(s)}</div></a>`;
}
// Tracks behind a card, for its play button and right-click menu.
async function cardTracks(c) {
const { kind, srv, key } = c.dataset;
const { kind, srv, key, dl } = c.dataset;
if (dl != null) return lists["dl:" + dl] || [];
if (kind === "playlist") return ((await px(srv, `/playlists/${key}/items`)).Metadata || []).map(m => track(srv, m));
return leaves(srv, key);
}
@@ -932,21 +933,28 @@ async function genres() {
}
const hue = s => [...s].reduce((h, c) => (h * 31 + c.charCodeAt(0)) % 360, 7);
// Downloads by the album or playlist they came from, newest first. Single songs go under Songs.
// Downloads the way iOS shows them: Playlists, Albums and Artists as card grids, then loose songs.
const DL_KINDS = [["Playlists", h => !/^#\/(album|artist)\//.test(h)], ["Albums", h => h.startsWith("#/album/")], ["Artists", h => h.startsWith("#/artist/")]];
function dlGroups(recs) {
const by = new Map();
const by = new Map(), loose = [];
for (const r of recs) {
const k = r.group?.href || "";
const k = r.group?.href;
if (!k) { loose.push(r); continue; }
if (!by.has(k)) by.set(k, { g: r.group, recs: [] });
by.get(k).recs.push(r);
}
const gs = [...by.values()].sort((a, b) => !a.g - !b.g);
return gs.map(({ g, recs }, n) => {
if (g) recs.sort((a, b) => a.saved - b.saved);
return `<section class="dlgroup"><div class="bar sm"><h2>${g ? `<a href="${esc(g.href)}">${esc(g.title)}</a>` : "Songs"}</h2>
<span class="sub">${plural(recs.length, "track")}, ${fmtBytes(recs.reduce((a, r) => a + r.size, 0))}</span><span class="grow"></span>
<button class="chip" data-dlgroup="${n}">Remove</button></div>${trackTable("dl:" + n, recs.map(r => r.track))}</section>`;
}).join("");
const gs = [...by.values()];
gs.forEach((x, n) => { x.n = n; x.recs.sort((a, b) => a.saved - b.saved); lists["dl:" + n] = x.recs.map(r => r.track); });
const tile = ({ g, recs, n }) => {
const t = recs[0].track, h = g.href, songs = plural(recs.length, "song");
const s = h.startsWith("#/album/") ? t.artist || "" : h.startsWith("#/artist/") ? songs : `Playlist · ${songs}`;
return card({ href: esc(h), img: artOf(t, 300), t: g.title, s, round: h.startsWith("#/artist/"), dl: n });
};
return DL_KINDS.map(([title, test]) => {
const list = gs.filter(x => test(x.g.href));
return list.length ? `<section class="dlgroup"><div class="bar sm"><h2>${title}</h2></div><div class="grid">${list.map(tile).join("")}</div></section>` : "";
}).join("") + (loose.length ? `<section class="dlgroup"><div class="bar sm"><h2>Other Songs</h2><span class="grow"></span>
<button class="chip" data-dlgroup="loose">Remove</button></div>${trackTable("dl:loose", loose.map(r => r.track))}</section>` : "");
}
// Albums whose original release date falls today (or within three days) in an earlier year.
@@ -1132,10 +1140,11 @@ const routes = {
if (my !== seq) return;
const total = recs.reduce((a, r) => a + r.size, 0);
const est = await navigator.storage?.estimate?.().catch(() => null);
lists["dl:all"] = recs.map(r => r.track);
view.innerHTML = bar("Downloads", { filter: false, extra: recs.length ? `<button class="chip" data-dlclear>Remove all</button>` : "" })
+ `<p class="note">${plural(recs.length, "track")}, ${fmtBytes(total)} stored in this browser${est?.quota ? ` (${fmtBytes(est.usage)} of ${fmtBytes(est.quota)} used)` : ""}.
+ `<p class="note">${plural(recs.length, "song")} · ${fmtBytes(total)} stored in this browser${est?.quota ? ` (${fmtBytes(est.usage)} of ${fmtBytes(est.quota)} used)` : ""}.
Downloads play without the network. ${isSecureContext ? "" : "This page isn't on HTTPS, so the browser may clear them when space runs low."}</p>`
+ (recs.length ? dlGroups(recs) : `<p class="empty-msg">Nothing downloaded.</p>`);
+ (recs.length ? actions("dl:all") + dlGroups(recs) : `<p class="empty-msg">Nothing downloaded. Right-click any playlist, album or artist and choose Download for offline.</p>`);
count(recs.length, "track");
},
async stems(my) {
@@ -1217,11 +1226,7 @@ view.addEventListener("click", async ev => {
S.stations = S.stations.filter(x => x.id !== ds.rddelete); save();
return route();
}
if (ds.dlgroup) {
const ts = lists["dl:" + ds.dlgroup] || [];
if (confirm(`Remove ${plural(ts.length, "download")}?`)) { for (const t of ts) await Offline.remove(t.id); emit("offline"); route(); }
return;
}
if (ds.dlgroup) return removeDl(ds.dlgroup, "these songs");
if ("shuffleall" in ds) {
const ts = (await new Pager(sources(), secPath, { type: 10, sort: "random" }, 200).next(200)).map(m => track(m._srv, m));
return Q.playList(visible(ts), -1, true);
@@ -1237,9 +1242,27 @@ view.addEventListener("click", async ev => {
if (ds.pldelete) { if (confirm("Delete this stem playlist?")) { playlists.splice(playlists.findIndex(x => x.id === ds.pldelete), 1); savePlaylists(); location.hash = "#/playlists"; } return; }
if ("dlclear" in ds) { if (confirm("Remove every download?")) { for (const id of [...Offline.ids]) await Offline.remove(id); emit("offline"); route(); } }
});
async function removeDl(n, what) {
const ts = lists["dl:" + n] || [];
if (!confirm(`Remove ${what} (${plural(ts.length, "download")})? They will no longer play offline.`)) return;
for (const t of ts) await Offline.remove(t.id);
emit("offline"); route();
}
function dlMenu(x, y, n, title) {
const ts = () => lists["dl:" + n] || [];
Menu.open(x, y, [
{ label: "Play", run: () => Q.playList(ts(), 0, false) },
{ label: "Shuffle", run: () => Q.playList(ts(), -1, true) },
{ label: "Play next", run: () => Q.add(ts(), true) },
{ label: "Add to queue", run: () => Q.add(ts()) },
"-",
{ label: "Remove download", run: () => removeDl(n, `“${title}”`) },
]);
}
view.addEventListener("contextmenu", ev => {
const row = ev.target.closest("tr[data-list]"), c = ev.target.closest(".card[data-kind]");
if (row) { ev.preventDefault(); trackMenu(ev.clientX, ev.clientY, row.dataset.list, +row.dataset.i); }
const row = ev.target.closest("tr[data-list]"), c = ev.target.closest(".card[data-kind]"), d = ev.target.closest(".card[data-dl]");
if (d) { ev.preventDefault(); dlMenu(ev.clientX, ev.clientY, d.dataset.dl, $(".t", d).textContent); }
else if (row) { ev.preventDefault(); trackMenu(ev.clientX, ev.clientY, row.dataset.list, +row.dataset.i); }
else if (c) { ev.preventDefault(); listMenu(ev.clientX, ev.clientY, () => cardTracks(c), { title: $(".t", c).textContent, href: c.getAttribute("href") }); }
});
+5 -5
View File
@@ -504,8 +504,8 @@ input[type=number]#precachen { width: 64px; background: var(--raised); border: 1
.actions + .bar.sm > * { pointer-events: auto; }
}
#volume { -webkit-appearance: none; appearance: none; height: 16px; background: none; cursor: pointer; }
#volume::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: #3c3f43; }
#volume::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: #e7e7e7; border: 0; }
#volume::-moz-range-track { height: 4px; border-radius: 2px; background: #3c3f43; }
#volume::-moz-range-progress { height: 4px; border-radius: 2px; background: #cccccc; }
#volume::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #e7e7e7; border: 0; }
#volume::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--accent) var(--v, 85%), color-mix(in srgb, var(--text) 22%, transparent) var(--v, 85%)); }
#volume::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: var(--text); border: 0; }
#volume::-moz-range-track { height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--text) 22%, transparent); }
#volume::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
#volume::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--text); border: 0; }