New overlay modules (taped-paper look, shared with the polaroid alerts): - cassette.js: redeems as a cassette tape; rarity = shell colour (Ultra Rare gold with glow, foil and sparkles), reels spin for the sound's length, sticker corner. - fx.js: Gigantify (viewer's emote grows giant), On-Screen Celebration (emote copies bounce around the screen), highlight / Message Effect (tall taped note). - poll.js: live poll card with bars, countdown and a WINNER stamp. - hypebar.js: persistent Hype Train strip (level, progress, time left). - raidcard.js: silent raid send-off card that stays during the raid countdown. - nowplaying.js: Feishin now-playing slip (not loaded yet, see overlay). polaroid.js: shared queue now also drives cassettes/effects; test alerts replace only other tests and never cut off real alerts; alerts stay up for the animation + 3 s or the sound's length; sound lengths measured in the browser for UI-picked sounds; tip and Hype Train alerts; optional ALERTS_BASE for offline test pages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.2 KiB
JavaScript
53 lines
2.2 KiB
JavaScript
/*
|
|
"Now playing" slip, top-right: taped paper with cover, title and artist. Visible exactly while a song is playing; hides on pause/stop.
|
|
NowPlaying.update(np) np: { playing, title, artist, album, cover (data URL or null) }
|
|
Small grace period on hide so skipping to the next song does not make it flicker.
|
|
*/
|
|
(function () {
|
|
const HIDE_GRACE_MS = 1500;
|
|
const esc = s => String(s ?? '').replace(/[&<>"]/g, c => ({ '&':'&', '<':'<', '>':'>', '"':'"' }[c]));
|
|
let el = null, shown = false, hideTimer = null, key = '';
|
|
|
|
function root() {
|
|
if (!el) {
|
|
el = document.createElement('div'); el.id = 'now-playing';
|
|
el.innerHTML = `<div class="slip"><div class="cover"></div><div class="txt"><div class="t"></div><div class="a"></div></div></div>`;
|
|
document.body.appendChild(el);
|
|
}
|
|
return el;
|
|
}
|
|
|
|
function show() {
|
|
clearTimeout(hideTimer);
|
|
if (shown) return;
|
|
shown = true; el.style.visibility = 'visible';
|
|
el.getAnimations().forEach(a => a.cancel());
|
|
el.animate([{ transform:'translateY(-140px)', opacity:0 }, { transform:'translateY(6px)', opacity:1, offset:.75 }, { transform:'translateY(0)', opacity:1 }],
|
|
{ duration:550, easing:'cubic-bezier(.2,.8,.3,1)' });
|
|
}
|
|
function hide() {
|
|
clearTimeout(hideTimer);
|
|
hideTimer = setTimeout(() => {
|
|
if (!shown) return;
|
|
shown = false;
|
|
el.animate([{ transform:'translateY(0)', opacity:1 }, { transform:'translateY(-140px)', opacity:0 }], { duration:450, easing:'ease-in', fill:'forwards' })
|
|
.finished.then(() => { if (!shown) el.style.visibility = 'hidden'; }).catch(() => {});
|
|
}, HIDE_GRACE_MS);
|
|
}
|
|
|
|
function update(np) {
|
|
root();
|
|
if (!np || !np.title) { hide(); return; }
|
|
const k = `${np.title}|${np.artist}`;
|
|
if (k !== key) {
|
|
key = k;
|
|
el.querySelector('.t').textContent = np.title;
|
|
el.querySelector('.a').textContent = np.artist || np.album || '';
|
|
el.querySelector('.cover').style.backgroundImage = np.cover ? `url("${np.cover}")` : '';
|
|
if (shown) el.querySelector('.slip').animate([{ opacity:.2, transform:'rotate(-1.5deg) translateX(14px)' }, { opacity:1, transform:'rotate(-1.5deg)' }], { duration:350 });
|
|
}
|
|
np.playing ? show() : hide();
|
|
}
|
|
|
|
window.NowPlaying = { update };
|
|
})();
|