heystreamer/public/alerts/raidcard.js
Bashy c481ca92cb Stats per stream and period, public stats page, dashboard settings, Card alert style
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>
2026-11-23 11:22:49 +02:00

64 lines
3.3 KiB
JavaScript

/*
Outgoing raid send-off card. Silent, outside the alert queue.
RaidCard.update(phase, raid) phase: start | done | cancel
raid: { target, avatar (Twitch profile picture URL or null), viewers, started_at }
start: appears and stays with a countdown (Twitch raids wait up to 90 s); done: "raid sent!" then leaves; cancel: leaves.
*/
(function () {
const COUNTDOWN_S = 90;
const BASE = window.ALERTS_BASE || '/alerts/';
// picture when the raided channel has none: Actions → Alerts → Raid send-off picture
const fallback = () => (window.S && window.S.alert_theme && window.S.alert_theme.raidFallback) || BASE + 'art/placeholder.svg';
const esc = s => String(s ?? '').replace(/[&<>"]/g, c => ({ '&':'&amp;', '<':'&lt;', '>':'&gt;', '"':'&quot;' }[c]));
let el = null, timer = null, hideTimer = null, startedAt = 0, shown = false;
function root() { if (!el) { el = document.createElement('div'); el.id = 'raid-card'; document.body.appendChild(el); } return el; }
function render(raid, line, badge) {
const img = raid.avatar ? `<img src="${esc(raid.avatar)}" alt="" onerror="this.onerror=null;this.className='fallback';this.src='${fallback()}'">`
: `<img class="fallback" src="${fallback()}" alt="">`;
el.innerHTML = `<div class="ph">${img}</div>
<div class="cap"><span class="u">raiding ${esc(raid.target)}</span>${esc(line)}</div>
<div class="when">${esc(badge)}</div>`;
}
function tick() {
const left = Math.max(0, COUNTDOWN_S - Math.round((Date.now() - startedAt) / 1000));
const w = el.querySelector('.when');
if (w) w.textContent = left ? `raid in ${Math.floor(left / 60)}:${String(left % 60).padStart(2, '0')}` : 'any second now…';
}
function enter() {
if (shown) return;
shown = true; el.style.visibility = 'visible';
el.getAnimations().forEach(a => a.cancel());
el.animate([{ transform:'translateY(-420px) rotate(-10deg)', opacity:0 }, { transform:'translateY(10px) rotate(2deg)', opacity:1, offset:.75 },
{ transform:'translateY(0) rotate(-1deg)', opacity:1 }], { duration:700, easing:'cubic-bezier(.2,.8,.3,1)', fill:'forwards' });
}
function leave(delay) {
clearTimeout(hideTimer);
hideTimer = setTimeout(() => {
clearInterval(timer);
el.animate([{ transform:'translateY(0) rotate(-1deg)', opacity:1 }, { transform:'translateX(700px) rotate(18deg)', opacity:0 }],
{ duration:700, easing:'ease-in', fill:'forwards' }).finished.then(() => { el.style.visibility = 'hidden'; shown = false; }).catch(() => {});
}, delay);
}
function update(phase, raid) {
root(); clearTimeout(hideTimer);
const viewers = raid.viewers != null ? `with ${raid.viewers} of you, be nice! ♡` : 'with all of you, be nice! ♡';
if (phase === 'start') {
startedAt = raid.started_at ? Date.parse(raid.started_at) : Date.now();
render(raid, viewers, '');
enter(); clearInterval(timer); timer = setInterval(tick, 500); tick();
} else if (phase === 'done') {
clearInterval(timer);
render(raid, 'raid sent! see you there ♡', 'GO GO GO');
enter(); leave(6000);
} else if (phase === 'cancel') {
clearInterval(timer);
if (!shown) return;
const w = el.querySelector('.when'); if (w) w.textContent = 'cancelled';
leave(1500);
}
}
window.RaidCard = { update };
})();