// Admin > Overview > Refill notices (2026-10-24): who was told their ads ran low, ran out or sat idle, and what they did next. (function () { const $ = id => document.getElementById(id); if (!$('rfBox')) return; const esc = s => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); const ct = ts => new Date(Number(ts)).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT'; const STATE = { low: 'running low', out: 'out of credits', idle: 'idle a week' }; async function load() { try { const r = await (await fetch('/api/admin/refill', { cache: 'no-store' })).json(); if (r.error) throw new Error(r.error); const t = r.totals || {}; $('rfSub').textContent = (r.enabled ? 'on' : 'OFF (site setting refillNotices)') + ', low at ' + r.lowPct + '% delivered'; const st = Object.entries(r.byState || {}).map(([k, v]) => esc(STATE[k] || k) + ': ' + v.sent + ' sent, ' + v.converted + ' acted').join(' · '); const kinds = Object.entries(r.byKind || {}).map(([k, v]) => esc(k) + ' ' + v).join(', '); $('rfBox').innerHTML = '

' + (t.sent || 0) + ' sent (' + (t.emailed || 0) + ' emailed), ' + (t.converted || 0) + ' acted on it (' + (t.ratePct || 0) + '%)' + (t.purchasesUsd ? ', $' + t.purchasesUsd + ' in packages after a notice' : '') + (t.medianHours != null ? ', median ' + t.medianHours + ' h' : '') + '

' + '

' + st + (kinds ? '
' + kinds : '') + '

' + ((r.recent || []).length ? '
' + r.recent.slice(0, 20).map(x => '').join('') + '
WhenOwnerStateAdsCredits thenNext
' + esc(ct(x.at)) + '' + esc(x.owner) + '' + esc(STATE[x.state] || x.state) + (x.emailed ? '' : ' (on-site only)') + '' + esc((x.names || []).join(', ')) + '' + Number(x.credits || 0).toLocaleString() + '' + (x.converted ? esc(x.converted.kind) + ' after ' + x.converted.hours + ' h' : 'nothing yet') + '
' : '

Nothing sent yet.

'); } catch (e) { $('rfBox').textContent = 'Could not load: ' + e.message; } } $('rfRun') && $('rfRun').addEventListener('click', async () => { $('rfRun').disabled = true; try { const r = await (await fetch('/api/admin/refill/run', { method: 'POST', cache: 'no-store' })).json(); $('rfSub').textContent = 'pass done: ' + (r.sent || 0) + ' sent'; } catch (e) {} $('rfRun').disabled = false; load(); }); load(); })();