diff options
Diffstat (limited to 'static')
| -rw-r--r-- | static/deck.css | 13 | ||||
| -rw-r--r-- | static/modules/xbox.js | 45 |
2 files changed, 54 insertions, 4 deletions
diff --git a/static/deck.css b/static/deck.css index 1bebd1a..02c91aa 100644 --- a/static/deck.css +++ b/static/deck.css @@ -962,7 +962,18 @@ dialog.vm-sheet::backdrop { background: color-mix(in srgb, var(--udt-crust) 55%, .xbox .xb-games { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; } .xbox .xb-game { display: flex; flex-direction: column; gap: 4px; min-width: 0; } .xbox .xb-gcover { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: var(--udt-surface0); } -.xbox .xb-gname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.xbox .xb-cap { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; } +.xbox .xb-ccover { aspect-ratio: 16 / 9; } +.xbox dialog.xb-view { margin: auto; width: min(1100px, 94vw); max-height: 92vh; padding: 14px; border: 0; + border-radius: 18px; background: var(--udt-base); color: var(--udt-text); } +.xbox .xb-vclose { position: absolute; top: 24px; right: 24px; border-radius: 50%; padding: 0; + background: color-mix(in srgb, var(--udt-crust) 70%, transparent); } +.xbox dialog.xb-view[open] { position: fixed; display: flex; flex-direction: column; gap: 12px; } +.xbox dialog.xb-view::backdrop { background: color-mix(in srgb, var(--udt-crust) 70%, transparent); } +.xbox .xb-vmedia { width: 100%; max-height: 75vh; object-fit: contain; border-radius: 12px; background: var(--udt-crust); } +.xbox .xb-vfoot { display: flex; align-items: center; justify-content: space-between; gap: 12px; } +.xbox .xb-vdl { display: inline-flex; align-items: center; padding: 0 18px; font-size: 1rem; font-weight: 600; text-decoration: none; } +.xbox .xb-gname {font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .xbox .xb-gmeta { color: var(--udt-subtext0); font-size: 0.857rem; } .xbox .xb-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; } .xbox .xb-list { display: flex; flex-direction: column; gap: 8px; } diff --git a/static/modules/xbox.js b/static/modules/xbox.js index 7c569ed..094b1c0 100644 --- a/static/modules/xbox.js +++ b/static/modules/xbox.js @@ -208,6 +208,37 @@ function gameTile(t) { return tile; } +// The viewer lives outside the redrawn part, so a data change leaves it open. +// The links are signed CDN URIs; the CDN answers octet-stream, so the link downloads. +function view(c, dlg) { + const media = c.kind === "clip" ? h("video", "xb-vmedia") : img(c.url, "xb-vmedia"); + if (c.kind === "clip") Object.assign(media, { src: c.url, controls: true, autoplay: true, playsInline: true }); + const a = h("a", "ib xb-vdl", "Download"); + a.href = c.url; + a.download = `${c.id}.${c.kind === "clip" ? "mp4" : "png"}`; + a.referrerPolicy = "no-referrer"; + const foot = h("div", "xb-vfoot"); + foot.append(h("div", "xb-gmeta", [c.title, new Date(c.date).toLocaleString(), + c.expires ? `kept until ${new Date(c.expires).toLocaleDateString()}` : null].filter(Boolean).join(" · "))); + foot.append(a); + const close = h("button", "ib nf xb-vclose", "\u{F0156}"); + close.setAttribute("aria-label", "Close"); + close.onclick = () => dlg.close(); + dlg.replaceChildren(media, foot, close); + dlg.onclose = () => dlg.replaceChildren(); // stops a clip still playing + dlg.showModal(); +} + +function captureTile(c, dlg) { + const tile = h("button", "xb-game xb-cap"); + const art = h("div", "xb-gart"); + art.append(img(c.thumb, "xb-gcover xb-ccover")); + if (c.kind === "clip") art.append(h("span", "xb-badge", `Clip · ${c.seconds ?? "?"} s`)); + tile.append(art, h("div", "xb-gname", c.title ?? ""), h("div", "xb-gmeta", ago(c.date))); + tile.onclick = () => view(c, dlg); + return tile; +} + function row(pic, title, sub, side, cls = "") { const r = h("div", `xb-row ${cls}`); const text = h("div", "xb-rtext"); @@ -240,7 +271,7 @@ function signIn(box, st) { box.append(wrap); } -function render(box, st) { +function render(box, st, dlg) { box.textContent = ""; const p = st.profile ?? {}; const head = h("div", "xb-head"); @@ -267,6 +298,13 @@ function render(box, st) { for (const t of st.titles ?? []) games.append(gameTile(t)); box.append(games); + if (st.captures?.length) { + box.append(h("div", "xb-section", "Captures")); + const caps = h("div", "xb-games"); + for (const c of st.captures) caps.append(captureTile(c, dlg)); + box.append(caps); + } + const lists = h("div", "xb-lists"); const ach = h("div", "xb-card xb-list"); ach.append(h("div", "xb-section", "Achievements")); @@ -288,7 +326,8 @@ export default { peek: (st) => sessionPeek(st), mount(el) { - el.innerHTML = '<div class="xbox"><div class="xb-off"></div><div class="xb-on"></div></div>'; + el.innerHTML = '<div class="xbox"><div class="xb-off"></div><div class="xb-on"></div>' + + '<dialog class="xb-view" closedby="any"></dialog></div>'; }, update(st, el) { @@ -315,7 +354,7 @@ export default { on._key = key; if (st.signed_in === false) signIn(on, st); else if (st.loading) on.replaceChildren(h("div", "xb-loading", "Loading Xbox Live…")); - else render(on, st); + else render(on, st, el.querySelector(".xb-view")); } const c = on.querySelector(".xb-clock"); if (c) c.textContent = clock(st.session); |
