Statistics - Per day and per stream statistics (src/periodstats.js, one generic stat_day table), backfilled once from the older tables; Stream / Week / Month / Year / All time views, Community and Streams tabs. - Viewer count every 5 minutes and title / category history per stream (EventSub channel.update): viewer graph, games played (donut), games in the streams list. - Twitch sync (src/twitchsync.js): followers with follow dates, current subs, mods, VIPs, all-time bits, channel emotes, past streams from VODs. Twitch analytics CSV import (src/twitchcsv.js). - Public stats page on its own host (Settings -> Stats and data): no message text, no bots, !hideme / !showme opt-out. Viewer page: roles, follow age, sub status, bits, a menu for rarely used actions. - StreamElements watch-time importer removed (already imported minutes stay as a baseline). Dashboard - Settings and Actions with a left sidebar; each settings page saves only its own fields. Connections (Twitch, StreamElements token now set here, HUDFX), OBS links (hidden behind an eye toggle) with a link builder, Chat (sound picked from the media library), TTS, Stats and data, Backup (export / import the whole setup), Advanced. Time zone setting for the stats pages. - Actions -> Alerts: alert style, pictures, sounds, bits tiers and card colours, stored in the database (src/theme.js); an old file-based theme is imported once. Alert preview page (/actions/alerts/preview, tools/preview/export.js for a static copy). - Old /actions page removed; Actions = Redeems / Alerts / TTS voices / Media. Alerts - New plain Card style for everyone (public/alerts/card.js); Polaroid, Cassette and the TTS letter stay as optional looks. Redeem variations can be Card, Cassette, Sound only or Video. Repo - No channel data in git: the channel's art, stickers and sounds stay on disk (gitignored) and are picked in the dashboard; examples for the server config (apache.example.sh, .env.example). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
78 lines
4.5 KiB
JavaScript
78 lines
4.5 KiB
JavaScript
/*
|
|
Card alerts: the plain style (Actions → Alerts: style "Card"). Used for events (follow, sub, gift, raid, bits, tip,
|
|
Hype Train) and for redeem variations / read-aloud redeems set to Card. Called by polaroid.js (shared queue):
|
|
window.CardAlert.show(d, cur, { url, len, volume }) -> Promise (resolves when it has left)
|
|
d: { art|sticker|emote (picture URL), name, line, msg, badge {big, small, color}, tag (small label above the name),
|
|
tts (voice URL instead of the sound), ttsEnv (loudness for word timing) }
|
|
cur: { anims, timer, audio } from polaroid.js, so reset / skip can stop it.
|
|
Timeline: slides in (0.6 s), sound starts, stays until the sound / voice ends (at least 4 s), slides out.
|
|
*/
|
|
(function () {
|
|
const MIN_SHOW = 4000, SOUND_LEAD = 350, ENV_STEP = 0.04;
|
|
const esc = s => String(s ?? '').replace(/[&<>"]/g, c => ({ '&':'&', '<':'<', '>':'>', '"':'"' }[c]));
|
|
let el = null;
|
|
function root() {
|
|
if (!el) { el = document.createElement('div'); el.id = 'card-alert'; document.body.appendChild(el); }
|
|
return el;
|
|
}
|
|
const theme = () => (window.S && window.S.alert_theme) || {};
|
|
|
|
function show(d, cur, { url, len, volume }) {
|
|
const el = root(), c = theme().card || {};
|
|
if (c.accent) el.style.setProperty('--accent', c.accent);
|
|
if (c.bg) el.style.setProperty('--bg', c.bg);
|
|
if (c.text) el.style.setProperty('--fg', c.text);
|
|
const pic = d.emote || d.sticker || d.art || '';
|
|
const name = d.name || 'Someone';
|
|
const words = d.tts && d.msg ? String(d.msg).split(/\s+/).filter(Boolean) : null;
|
|
el.innerHTML = `<div class="card${d.badge ? ' has-badge' : ''}">
|
|
<div class="pic">${pic ? `<img src="${esc(pic)}" alt="">` : `<span class="ini">${esc(name.trim()[0] || '♥').toUpperCase()}</span>`}</div>
|
|
<div class="txt">
|
|
${d.tag ? `<div class="tag">${esc(d.tag)}</div>` : ''}
|
|
<div class="name">${esc(name)}</div>
|
|
<div class="line">${esc(d.line || '')}</div>
|
|
${d.msg ? `<div class="msg">${words ? words.map(w => `<span class="w">${esc(w)}</span>`).join(' ') : `“${esc(d.msg)}”`}</div>` : ''}
|
|
</div>
|
|
${d.badge ? `<div class="badge"${d.badge.color ? ` style="--badge:${esc(d.badge.color)}"` : ''}>${esc(d.badge.big)}<small>${esc(d.badge.small || '')}</small></div>` : ''}
|
|
<div class="bar"></div>
|
|
</div>`;
|
|
el.style.visibility = 'visible';
|
|
const card = el.querySelector('.card');
|
|
const A = (node, frames, opts) => { const a = node.animate(frames, { fill:'both', ...opts }); cur.anims.push(a); return a; };
|
|
|
|
A(card, [
|
|
{ transform:'translateX(-700px)', opacity:0 },
|
|
{ transform:'translateX(14px)', opacity:1, offset:.75 },
|
|
{ transform:'translateX(0)', opacity:1 },
|
|
], { duration:600, easing:'cubic-bezier(.2,.8,.3,1)' });
|
|
A(el.querySelector('.pic'), [{ transform:'scale(.6) rotate(-8deg)' }, { transform:'scale(1.08) rotate(3deg)', offset:.6 }, { transform:'scale(1) rotate(0)' }],
|
|
{ delay:350, duration:450, easing:'ease-out' });
|
|
|
|
// the voice (read-aloud redeems) or the sound
|
|
const voice = d.tts || null;
|
|
const playUrl = voice || url;
|
|
const playLen = voice ? (d.ttsMs || 0) : len;
|
|
if (playUrl) {
|
|
const a = new Audio(playUrl); a.volume = volume;
|
|
cur.timer = setTimeout(() => { cur.audio = a; a.play().catch(err => console.warn('[alerts] sound blocked:', err.message)); }, SOUND_LEAD);
|
|
// words light up roughly as they are spoken
|
|
if (words) {
|
|
const spans = [...el.querySelectorAll('.msg .w')];
|
|
const total = Math.max(playLen, 1000), step = total / Math.max(spans.length, 1);
|
|
spans.forEach((s, i) => setTimeout(() => s.classList.add('on'), SOUND_LEAD + i * step));
|
|
}
|
|
} else if (words) el.querySelectorAll('.msg .w').forEach(s => s.classList.add('on'));
|
|
|
|
const stay = Math.max(MIN_SHOW, playUrl ? SOUND_LEAD + playLen + 600 : 0);
|
|
A(el.querySelector('.bar'), [{ transform:'scaleX(1)' }, { transform:'scaleX(0)' }], { delay:600, duration:Math.max(stay - 600, 500), easing:'linear' });
|
|
const exit = A(card, [
|
|
{ transform:'translateX(0)', opacity:1 },
|
|
{ transform:'translateX(18px)', opacity:1, offset:.25 },
|
|
{ transform:'translateX(-720px)', opacity:0 },
|
|
], { delay:stay, duration:550, easing:'cubic-bezier(.5,0,.8,.4)' });
|
|
return exit.finished.then(() => { el.style.visibility = 'hidden'; cur.anims.forEach(a => a.cancel()); }).catch(() => {});
|
|
}
|
|
|
|
function hide() { if (el) el.style.visibility = 'hidden'; }
|
|
window.CardAlert = { show, hide };
|
|
})();
|