Mystery Hunt Box + Ad Detective, badge tiers

Finish the day's Code Hunts to unlock one box a day. It opens to an Ad
Detective case on one site with a fixed 0.15 POL reward shown up front:
visit (the embed records the visit after the dwell, no code), then answer
one question, one attempt. Paid inside the house cap, never counted as a
find. 34-question bank seeded from lib/detective-bank.json; a hunter never
repeats a question until they have seen every one for that site. Admin
panel with per-question stats and retire/restore.

New badges (all ledger-derived): Detective, Sleuth, Investigator, Master
Detective; Scout, Guide, Trail Boss; Week Sweep; 7-Day Streak. Badges
already earned on deploy are marked announced without posting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-26 16:10:17 -05:00
parent 64ab0b505f
commit 469cbf69a5
25 changed files with 1334 additions and 423 deletions
+13 -1
View File
@@ -31,6 +31,10 @@
<div style="margin-top:12px"><button class="btn sm" id="saveMission">Save mission</button> <span id="missionMsg" style="font-size:13px;color:var(--muted)"></span></div></div>
<table id="missions" style="margin-top:14px"></table>
</section>
<section class="section"><h2>Ad Detective</h2>
<div class="sub" id="detLine"></div>
<table id="detQs" style="margin-top:10px"></table>
</section>
<section class="section"><h2>Recent drips</h2><table id="payouts"></table></section>
</div>
</div>
@@ -51,7 +55,15 @@
document.querySelectorAll('[data-del]').forEach(b => b.addEventListener('click', async () => { if (!confirm('Delete mission ' + b.dataset.del + '?')) return; await api('/api/admin/mission', { method: 'DELETE', body: JSON.stringify({ id: b.dataset.del }) }); load(); }));
document.querySelectorAll('[data-test]').forEach(b => b.addEventListener('click', async () => { const r = await api('/api/admin/embed-test?id=' + encodeURIComponent(b.dataset.test)); if (r.url) { window.open(r.url, '_blank', 'noopener'); alert('Opened with a test token. The code renders after ' + r.dwell + 's.'); } else alert(r.error || 'failed'); }));
}
$('go').addEventListener('click', () => { KEY = $('key').value.trim(); load(); });
// Ad Detective: today's boxes, and per question how often it was asked and answered right. A question
// most people get wrong is unclear; one nearly everyone gets right after many asks may be shared around.
async function loadDetective() {
const d = await api('/api/admin/detective'); if (!d || !d.questions) return;
$('detLine').textContent = 'Reward ' + d.settings.pol + ' POL · ' + (d.settings.on ? 'on' : 'OFF') + ' · today: ' + d.today.boxes + ' boxes, ' + d.today.won + ' solved, ' + d.today.missed + ' missed · ' + d.questions.filter(q => q.active !== false).length + ' active questions';
$('detQs').innerHTML = '<tr><th>site</th><th>question</th><th>right answer</th><th>asked</th><th>right</th><th></th></tr>' + d.questions.map(q => '<tr style="' + (q.active === false ? 'opacity:.45' : '') + '"><td class="num">' + esc(q.missionId) + '</td><td>' + esc(q.q) + '</td><td>' + esc(q.options[0]) + '</td><td class="num">' + q.asked + '</td><td class="num">' + (q.asked ? Math.round(100 * q.correct / q.asked) + '%' : '—') + '</td><td><button class="btn ghost sm" data-qa="' + esc(q.id) + '" data-on="' + (q.active === false ? '1' : '0') + '">' + (q.active === false ? 'restore' : 'retire') + '</button></td></tr>').join('');
document.querySelectorAll('[data-qa]').forEach(b => b.addEventListener('click', async () => { await api('/api/admin/detective/question', { method: 'POST', body: JSON.stringify({ id: b.dataset.qa, active: b.dataset.on === '1' }) }); loadDetective(); }));
}
$('go').addEventListener('click', () => { KEY = $('key').value.trim(); load(); loadDetective(); });
$('key').addEventListener('keydown', e => { if (e.key === 'Enter') $('go').click(); });
$('saveSettings').addEventListener('click', async () => { const b = {}; for (const k of ['minPol', 'maxPol', 'dailyCapPol', 'lowBalancePol']) b[k] = Number($(k).value); const r = await api('/api/admin/settings', { method: 'POST', body: JSON.stringify(b) }); if (r.error) alert(r.error); load(); });
$('tickFaucet').addEventListener('click', async () => { $('faucetLine').textContent = 'running…'; const r = await api('/api/admin/faucet/tick', { method: 'POST' }); $('faucetLine').textContent = r.error ? r.error : 'paid ' + r.paid + ' · balance ' + (r.balance == null ? '—' : Number(r.balance).toFixed(4) + ' POL'); load(); });