diff --git a/web/app.js b/web/app.js index 1aaa621..734902a 100644 --- a/web/app.js +++ b/web/app.js @@ -519,7 +519,7 @@ $("#b-mixer").innerHTML = ICON.mixer; $("#b-lyrics").innerHTML = ICON.lyrics; $("#b-queue").innerHTML = ICON.queue; $("#speed").innerHTML = SPEEDS.map(v => ``).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 ` -
${src ? `` : `
`}${kind ? `` : ""}
${esc(t)}
${esc(s)}
`; + return ` +
${src ? `` : `
`}${kind || dl != null ? `` : ""}
${esc(t)}
${esc(s)}
`; } // 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 `

${g ? `${esc(g.title)}` : "Songs"}

- ${plural(recs.length, "track")}, ${fmtBytes(recs.reduce((a, r) => a + r.size, 0))} -
${trackTable("dl:" + n, recs.map(r => r.track))}
`; - }).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 ? `

${title}

${list.map(tile).join("")}
` : ""; + }).join("") + (loose.length ? `

Other Songs

+
${trackTable("dl:loose", loose.map(r => r.track))}
` : ""); } // 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 ? `` : "" }) - + `

${plural(recs.length, "track")}, ${fmtBytes(total)} stored in this browser${est?.quota ? ` (${fmtBytes(est.usage)} of ${fmtBytes(est.quota)} used)` : ""}. + + `

${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."}

` - + (recs.length ? dlGroups(recs) : `

Nothing downloaded.

`); + + (recs.length ? actions("dl:all") + dlGroups(recs) : `

Nothing downloaded. Right-click any playlist, album or artist and choose Download for offline.

`); 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") }); } }); diff --git a/web/style.css b/web/style.css index 25947bb..39151f7 100644 --- a/web/style.css +++ b/web/style.css @@ -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; }