Overlays refresh themselves after updates; media URLs versioned; frameless (transparent) alerts
- Overlay\Build id (plugin version + admin epoch) in X-SG-Build; overlay.js reloads once on mismatch (loop-guarded); 'Refresh all overlays now' - Media URLs carry ?v=<mtime> - Alert option 'Frameless' (schema v5): no box so transparent PNG/GIF/WebP and VP9-alpha WebM show through; admin preview with checkerboard and ffmpeg help Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9249b80cb6
commit
afa768fa42
21 files changed
+287
-16
No files matched your search
@@ -21,3 +21,13 @@
|
||||
.sga-alert-media img,.sga-alert-media video{max-height:180px}
|
||||
.sga-media .button{min-height:40px}
|
||||
}
|
||||
|
||||
/* Frameless alerts: preview backdrops and card without the box */
|
||||
.sga-bg-light{background:repeating-conic-gradient(#e8e8ee 0 25%,#fff 0 50%) 0 0/20px 20px;color:#111}
|
||||
.sga-bg-scene{background:linear-gradient(135deg,#1e6f3c 0 33%,#c2410c 33% 66%,#1d4ed8 66%)}
|
||||
.sga-alert.sga-frameless{background:none;border:0;padding:0}
|
||||
.sga-frameless .sga-alert-head{text-shadow:0 0 3px #000,0 0 6px #000,0 1px 4px #000}
|
||||
.sga-bg-light .sga-frameless .sga-alert-head{text-shadow:0 0 3px #fff,0 0 6px #fff;color:#111}
|
||||
.sga-howto{margin-top:8px}
|
||||
.sga-howto pre{overflow-x:auto;max-width:100%;padding:8px;background:#f0f0f1}
|
||||
.sga-bg-pick{margin-left:12px}
|
||||
@@ -110,7 +110,8 @@
|
||||
var vals = { name: 'Alex', amount: money( amt || 500 ), reward: reward };
|
||||
var msg = render( form.elements.message.value, vals );
|
||||
|
||||
var card = el( 'div', 'sga-alert' );
|
||||
var frameless = !! ( visUrl && form.elements.frameless && form.elements.frameless.checked );
|
||||
var card = el( 'div', 'sga-alert' + ( frameless ? ' sga-frameless' : '' ) );
|
||||
var isVideo = /^video\//.test( visMime ), video = null;
|
||||
if ( visUrl ) {
|
||||
var box = el( 'div', 'sga-alert-media' );
|
||||
@@ -145,6 +146,10 @@
|
||||
timers.push( setTimeout( end, dur ) );
|
||||
}
|
||||
}
|
||||
/* Preview backdrop: dark / light checkerboard or a busy "scene" so transparency is visible. */
|
||||
var bgSel = document.getElementById( 'sga-bg' );
|
||||
function setBg() { stage.className = 'sga-stage' + ( bgSel && bgSel.value !== 'dark' ? ' sga-bg-' + bgSel.value : '' ); }
|
||||
if ( bgSel ) { bgSel.addEventListener( 'change', setBg ); }
|
||||
playBtn.addEventListener( 'click', play );
|
||||
stage.appendChild( el( 'span', 'sga-idle', 'Press "Play preview".' ) );
|
||||
}() );
|
||||
@@ -59,3 +59,13 @@ body.sg-offline #sg-root{opacity:.6}
|
||||
@keyframes sg-tier-pop{0%{transform:scale(1)}30%{transform:scale(1.06)}100%{transform:scale(1)}}
|
||||
@keyframes sg-tier-glow{0%,100%{box-shadow:0 0 0 transparent}50%{box-shadow:0 0 1em #f59e0b,0 0 2em var(--sg-accent2)}}
|
||||
@media (prefers-reduced-motion:reduce){.sg-card.sg-tier-up{animation:none;box-shadow:0 0 .8em #f59e0b}}
|
||||
|
||||
/* Frameless alerts (transparent PNG/GIF/WebP/WebM): no box, border or glow; media fits the window; text gets an outline. */
|
||||
.sg-alert.sg-frameless{background:none;border:0;box-shadow:none;padding:0;max-height:100%;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;min-height:0}
|
||||
.sg-alert.sg-frameless.sg-bonus{border:0;animation:sg-in .6s cubic-bezier(.22,1,.36,1) both}
|
||||
.sg-alert.sg-frameless.sg-bonus.sg-out,.sg-alert.sg-frameless.sg-out{animation:sg-out .5s ease-in both}
|
||||
.sg-frameless .sg-alert-media{flex:0 1 auto;min-height:0;max-width:100%;max-height:100%;margin-bottom:.2em;overflow:hidden}
|
||||
.sg-frameless .sg-alert-media img,.sg-frameless .sg-alert-media video{max-width:100%;max-height:calc(100vh - 9em);width:auto;height:auto;object-fit:contain;border-radius:0;background:transparent}
|
||||
.sg-frameless .sg-alert-head,.sg-frameless .sg-alert-msg,.sg-frameless .sg-bonus-line{text-shadow:0 0 .06em #000,0 0 .12em #000,0 0 .2em #000,0 .04em .3em #000,.04em 0 0 #000,-.04em 0 0 #000,0 .04em 0 #000,0 -.04em 0 #000}
|
||||
.sg-theme-light .sg-frameless .sg-alert-head,.sg-theme-light .sg-frameless .sg-alert-msg{text-shadow:0 0 .06em #fff,0 0 .12em #fff,0 0 .2em #fff,.04em 0 0 #fff,-.04em 0 0 #fff,0 .04em 0 #fff,0 -.04em 0 #fff}
|
||||
@media (prefers-reduced-motion:reduce){.sg-alert.sg-frameless,.sg-alert.sg-frameless.sg-out,.sg-alert.sg-frameless.sg-bonus,.sg-alert.sg-frameless.sg-bonus.sg-out{animation:none;box-shadow:none}}
|
||||
@@ -5,6 +5,7 @@
|
||||
var endpoint = body.getAttribute('data-endpoint');
|
||||
var poll = Math.max(1000, parseInt(body.getAttribute('data-poll'), 10) || 2500);
|
||||
var root = document.getElementById('sg-root');
|
||||
var build = body.getAttribute('data-build') || '';
|
||||
var etag = null, failures = 0, skew = 0, timerState = null;
|
||||
var queue = [], showing = false;
|
||||
|
||||
@@ -151,7 +152,7 @@
|
||||
if (!v && !s && !msg) return null;
|
||||
var vol = Number(m.volume); if (!isFinite(vol)) vol = 80;
|
||||
var dur = Number(m.duration_ms); if (!isFinite(dur) || dur <= 0) dur = DEFAULT_HOLD;
|
||||
return { visual: v, sound: s, volume: Math.max(0, Math.min(100, vol)) / 100, duration: Math.max(1000, Math.min(60000, dur)), message: msg };
|
||||
return { frameless: !!(v && m.frameless === true), visual: v, sound: s, volume: Math.max(0, Math.min(100, vol)) / 100, duration: Math.max(1000, Math.min(60000, dur)), message: msg };
|
||||
}
|
||||
// Loads visual + sound before the card appears (no flash of an empty frame). Anything that fails or takes
|
||||
// longer than MEDIA_TIMEOUT is dropped, so the alert falls back to text and the queue never stalls.
|
||||
@@ -212,6 +213,7 @@
|
||||
box.appendChild(vis);
|
||||
card.appendChild(box);
|
||||
card.classList.add('sg-has-media');
|
||||
if (m && m.frameless) card.classList.add('sg-frameless');
|
||||
}
|
||||
if (m && m.message) {
|
||||
head.textContent = m.message;
|
||||
@@ -364,6 +366,33 @@
|
||||
var delay = failures ? Math.min(15000, poll * Math.pow(2, Math.min(failures, 3))) : poll;
|
||||
setTimeout(tick, delay);
|
||||
}
|
||||
// Self-refresh: every overlay response carries the current build id (plugin version + admin epoch) in X-SG-Build.
|
||||
// A different value than the one this page was rendered with means the page is stale (OBS never reloads a
|
||||
// running source after an update), so reload once. Guard: at most one reload per build per 30 s, remembered in
|
||||
// sessionStorage, or in a module flag when storage is blocked. Applies to 200 and 304 responses alike.
|
||||
var RELOAD_GUARD_MS = 30000, reloadTried = {};
|
||||
// sessionStorage first; if it is blocked, window.name (which also survives a reload) carries the marker, so a
|
||||
// blocked-storage source cannot reload in a loop. The module-level reloadTried only covers one page life.
|
||||
function readGuard(key) {
|
||||
try { return JSON.parse(sessionStorage.getItem(key) || 'null'); } catch (e) { /* fall through */ }
|
||||
try { var m = /(?:^|;)sg_reload=([^;]*)/.exec(window.name || ''); return m ? JSON.parse(decodeURIComponent(m[1])) : null; } catch (e2) { return null; }
|
||||
}
|
||||
function writeGuard(key, v) {
|
||||
try { sessionStorage.setItem(key, JSON.stringify(v)); return; } catch (e) { /* fall through */ }
|
||||
try { window.name = (window.name || '').replace(/(?:^|;)sg_reload=[^;]*/, '') + ';sg_reload=' + encodeURIComponent(JSON.stringify(v)); } catch (e2) { /* module flag only */ }
|
||||
}
|
||||
function checkBuild(r) {
|
||||
var b = null;
|
||||
try { b = r.headers.get('X-SG-Build'); } catch (e) { return false; }
|
||||
if (!b || !build || b === build) return false;
|
||||
var now = Date.now(), key = 'sg_overlay_reload', last = readGuard(key);
|
||||
var seen = last && last.b === b ? Number(last.t) : 0;
|
||||
if (reloadTried[b] && reloadTried[b] > seen) seen = reloadTried[b];
|
||||
if (seen && now - seen < RELOAD_GUARD_MS && now >= seen) return false;
|
||||
reloadTried[b] = now;
|
||||
writeGuard(key, { b: b, t: now });
|
||||
try { location.reload(); return true; } catch (e3) { return false; }
|
||||
}
|
||||
function tick() {
|
||||
var ctrl = typeof AbortController === 'function' ? new AbortController() : null;
|
||||
var to = ctrl ? setTimeout(function () { ctrl.abort(); }, 8000) : 0;
|
||||
@@ -372,6 +401,7 @@
|
||||
fetch(url(), { headers: headers, cache: 'no-store', signal: ctrl ? ctrl.signal : undefined })
|
||||
.then(function (r) {
|
||||
clearTimeout(to);
|
||||
if (checkBuild(r)) return null;
|
||||
if (r.status === 304) return null;
|
||||
if (!r.ok) throw new Error('http ' + r.status);
|
||||
var et = r.headers.get('ETag');
|
||||
|
||||
Reference in new issue
Block a user