// Admin (2026-11-16): spot takedown and restore with a required reason, and the admin ledger. Read with the ADMIN_TOKEN (kept in this tab only). (function () { BL.renderNav(''); const $ = BL.$, esc = BL.esc; let tok = ''; try { tok = sessionStorage.getItem('bl.admin') || ''; } catch (e) {} const get = u => BL.getJSON(u, { headers: { 'x-admin-token': tok } }); const send = (u, body) => BL.getJSON(u, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-admin-token': tok }, body: JSON.stringify(body) }); const ct = t => t ? new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago' }) + ' CT' : ''; const who = x => x.username ? '@' + x.username : BL.short(x.owner || ''); async function open() { const s = await get('/api/admin/actions?n=1'); if (s.error) { BL.status('That token was not accepted.', 'err'); return; } try { sessionStorage.setItem('bl.admin', tok); } catch (e) {} $('tokCard').hidden = true; $('adm').hidden = false; BL.status(''); actions(); } async function actions() { const a = await get('/api/admin/actions?n=200'); if (a.error) return; $('aActions').innerHTML = a.actions.length ? '' + a.actions.map(e => '').join('') + '
WhenActionSpotOwnerByReasonCredit
' + esc(ct(e.at)) + '' + esc(e.action) + '#' + e.spotId + '' + esc(who(e)) + '' + esc(e.by) + '' + esc(e.reason || '') + '' + esc(e.credit) + '
' : '

No takedowns yet.

'; } async function find() { const q = $('spQ').value.trim(); if (!q) return; const d = await get('/api/admin/spots?q=' + encodeURIComponent(q)); if (d.error) { $('spList').innerHTML = '

' + esc(d.error) + '

'; return; } $('spList').innerHTML = ''; for (const s of d.spots) { const el = document.createElement('div'); el.className = 'spot-ed adm-spot'; const st = s.down ? 'TAKEN DOWN ' + ct(s.down.at) + ' by ' + s.down.by + ': ' + s.down.reason + ' (no credit)' : 'Showing (' + s.showing.from + ')'; const edits = s.edits.length ? '
' + s.edits.length + ' edit' + (s.edits.length === 1 ? '' : 's') + ' (newest first)' + s.edits.map(e => '').join('') + '
WhenWhatOldNew
' + esc(ct(e.at)) + '' + esc(e.what) + ' (' + esc(e.via) + ')' + esc(e.old.link) + '
' + esc(e.old.img) + '
' + esc(e.new.link) + '
' + esc(e.new.img) + '
' : '

No edits yet.

'; el.innerHTML = '
Spot #' + s.id + '' + esc(who(s)) + ' ' + esc(s.owner) + '
' + '

' + esc(st) + '
Link: ' + esc(s.link || '(default or none)') + '
' + s.views + ' of ' + s.owed + ' views, ' + (s.clicks.organic + s.clicks.gate) + ' clicks. Bought ' + esc(ct(s.boughtAt)) + '.' + (s.downs.length ? ' Restored before: ' + s.downs.length + 'x.' : '') + '

' + edits + '
'; el.querySelector('.lots').appendChild(BL.tile({ t: 'x', img: s.img || s.showing.img, href: '#' })); const act = el.querySelector('.act'); if (s.down) { act.innerHTML = '
'; act.querySelector('button').onclick = async () => { const r = await send('/api/admin/spots/' + s.id + '/restore', { reason: act.querySelector('.rs').value }); BL.status(r.error || ('Spot #' + s.id + ' restored.'), r.error ? 'err' : 'ok'); find(); actions(); }; } else if (s.kind !== 3) { act.innerHTML = '
' + '
' + '
'; const bt = act.querySelector('button'); bt.onclick = async () => { const reason = act.querySelector('.why').value.trim(); if (reason.length < 3) return BL.status('Write the reason first.', 'err'); if (!bt.dataset.armed) { bt.dataset.armed = '1'; bt.textContent = 'Click again to take down #' + s.id; setTimeout(() => { if (bt.isConnected) { delete bt.dataset.armed; bt.textContent = 'Take down'; } }, 8000); return; } const r = await send('/api/admin/spots/' + s.id + '/takedown', { reason, credit: 'none' }); BL.status(r.error || ('Spot #' + s.id + ' taken down, no credit.'), r.error ? 'err' : 'ok'); find(); actions(); }; } $('spList').appendChild(el); } } $('spFind').onclick = find; $('spQ').addEventListener('keydown', e => { if (e.key === 'Enter') find(); }); $('tokBtn').onclick = () => { tok = $('tok').value.trim(); open(); }; $('tok').addEventListener('keydown', e => { if (e.key === 'Enter') $('tokBtn').click(); }); if (tok) open(); })();