restore SREBOT/web/ accidentally wiped by auto-merge #1258 (#1259)

This commit is contained in:
NotSoToothless
2026-05-18 12:28:23 -07:00
committed by GitHub
parent 47ae8b92f7
commit f7b5538d7b
136 changed files with 49022 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
(function () {
'use strict';
const modal = document.getElementById('season-recap-modal');
const btn = document.getElementById('season-recap-btn');
const selectEl = document.getElementById('season-recap-select');
const genBtn = document.getElementById('season-recap-generate');
const img = document.getElementById('season-recap-image');
const statusEl = document.getElementById('season-recap-status');
if (!modal || !btn || !selectEl || !genBtn || !img) {
console.warn('[recap-player] modal elements not found; skipping init');
return;
}
const scriptTag = document.currentScript;
const uid = scriptTag && scriptTag.dataset.uid;
if (!uid) {
console.warn('[recap-player] no uid on script tag; disabling button');
btn.disabled = true;
return;
}
function openModal() {
modal.classList.remove('hidden');
modal.setAttribute('aria-hidden', 'false');
}
function closeModal() {
modal.classList.add('hidden');
modal.setAttribute('aria-hidden', 'true');
}
modal.querySelectorAll('[data-close]').forEach(el => el.addEventListener('click', closeModal));
btn.addEventListener('click', async () => {
openModal();
if (!selectEl.options.length) await loadSeasons();
});
function t(key) {
return (window.__t && window.__t('seasonCard.' + key)) || key;
}
async function loadSeasons() {
statusEl.textContent = t('loadingSeasons');
try {
if (!window.apiClient) throw new Error('apiClient not available');
const seasons = await window.apiClient.request('/api/seasons');
const entries = Object.entries(seasons).sort((a, b) => b[1].start - a[1].start);
selectEl.innerHTML = '';
for (const [name, range] of entries) {
const opt = document.createElement('option');
opt.value = name;
opt.textContent = range.status === 'in_progress'
? `${name} ${t('inProgressSuffix')}`
: name;
selectEl.appendChild(opt);
}
statusEl.textContent = '';
} catch (err) {
console.error('[recap-player] seasons fetch failed:', err);
statusEl.textContent = t('failedSeasons');
}
}
function selectedTheme() {
const checked = document.querySelector('input[name="season-recap-theme"]:checked');
return (checked && checked.value) || 'dark';
}
genBtn.addEventListener('click', () => {
const season = selectEl.value;
if (!season) return;
const theme = selectedTheme();
const lang = document.documentElement.lang || 'en';
const base = `/players/${encodeURIComponent(uid)}/recap/${encodeURIComponent(season)}.png`;
const params = new URLSearchParams({ theme, lang });
statusEl.textContent = t('generating');
img.style.display = 'none';
img.onload = () => {
statusEl.textContent = '';
img.style.display = 'block';
};
img.onerror = () => {
statusEl.textContent = t('failedGenerate');
};
const currentOpt = selectEl.options[selectEl.selectedIndex];
const inProgressLabel = t('inProgressSuffix');
const isInProgress = !!(currentOpt && inProgressLabel && currentOpt.textContent.indexOf(inProgressLabel) !== -1);
if (isInProgress) params.set('t', String(Date.now()));
img.src = `${base}?${params.toString()}`;
});
})();