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
+41 -2
View File
@@ -148,10 +148,12 @@
$('copylink').onclick = () => copy($('mylink'), $('copylink')); $('copytext').onclick = () => copy($('sharetext'), $('copytext'));
}
watchPaid(); if (seenLedger === null) watchLedger();
doneNudge(board.daily);
// the Mystery Hunt Box comes first: the nudge back to InstantAdPay waits until today's case is closed
{ const bx = board.box; if (!bx || !bx.on || bx.status === 'won' || bx.status === 'missed') doneNudge(board.daily); }
fridayCard(board.fridayBank);
boxCard(board.box);
const dl = board.daily; if (dl && $('rangeLine')) $('rangeLine').innerHTML = ($('rangeLine').textContent.replace(/\s*·\s*You have.*$/, '')) + ' \u00b7 ' + (dl.left ? 'You have <b>' + dl.left + ' of ' + dl.limit + '</b> missions left today.' : '<b>That is your ' + dl.limit + ' for today.</b> Fresh missions at midnight Central.');
$('mine').innerHTML = board.drips.length ? board.drips.map(d => '<div class="row"><span>' + esc(d.site) + '</span><span class="site">' + ({ paid: 'paid', sent: 'sending', due: 'paying next', queued: 'queued for the next pool', failed: 'held, being looked at' }[d.status] || d.status) + '</span><span class="pol">+' + d.pol + ' POL</span>' + (d.tx ? '<a class="when" target="_blank" rel="noopener" href="' + explorer + '/tx/' + d.tx + '">verify ↗</a>' : '<span class="when"></span>') + '</div>').join('')
$('mine').innerHTML = board.drips.length ? board.drips.map(d => '<div class="row"><span>' + (String(d.missionId || '').startsWith('detective:') ? '\u{1F50E} ' : '') + esc(d.site) + '</span><span class="site">' + ({ paid: 'paid', sent: 'sending', due: 'paying next', queued: 'queued for the next pool', failed: 'held, being looked at' }[d.status] || d.status) + '</span><span class="pol">+' + d.pol + ' POL</span>' + (d.tx ? '<a class="when" target="_blank" rel="noopener" href="' + explorer + '/tx/' + d.tx + '">verify ↗</a>' : '<span class="when"></span>') + '</div>').join('')
: '<div class="row"><span class="site">Nothing yet. Your first find goes here.</span></div>';
document.querySelectorAll('[data-start]').forEach(b => b.addEventListener('click', () => start(b.dataset.start)));
const s = $('submit'); if (s) { s.addEventListener('click', submit); $('code').addEventListener('keydown', e => { if (e.key === 'Enter') submit(); }); tick(); }
@@ -202,6 +204,43 @@
+ '<div>' + chips + '</div><div style="font-size:14px;color:var(--muted)">' + line + '</div>';
el.hidden = false;
}
// Mystery Hunt Box + Ad Detective (2026-09-26): unlocked by finishing today's Code Hunts, opens to
// a case on one site with a fixed reward shown up front, one question, one answer.
let boxPoll = null;
// refresh only the box, so a code being typed into an open mission is never wiped
async function boxRefresh() { const b = await api('/api/my/board'); if (b && b.me) { board.box = b.box; boxCard(board.box); } }
function boxCard(bx) {
const el = $('boxSlot'); if (!el) return;
clearTimeout(boxPoll);
if (!bx || !bx.on || !board.me.wallet) { el.hidden = true; return; }
const pol = bx.pol + ' POL';
const head = t => '<div class="box-hd">\u{1F381} Mystery Hunt Box</div><h3>' + t + '</h3>';
const rule = '<p class="box-rule">One answer only. Look carefully before answering.</p>';
let h = '';
if (bx.status === 'locked') h = head('Unlocks when today’s hunts are done') + '<p>Find all ' + bx.need + ' of today’s codes and your box opens: a bonus case worth a fixed <b>' + pol + '</b>. <span class="box-dim">' + bx.done + ' of ' + bx.need + ' found.</span></p>';
else if (bx.status === 'ready') h = head('Your box is ready') + '<p>Open it to see today’s bonus case. It pays a fixed <b>' + pol + '</b> and does not use up a mission.</p><button class="btn pol" id="boxOpen">Open the box</button>';
else if (bx.status === 'open') h = head('\u{1F50E} Ad Detective on ' + esc(bx.site)) + '<p>Reward: <b>' + pol + '</b>, fixed. Visit the site and look around for at least ' + bx.dwell + ' seconds. Then come back here and answer <b>one question</b> about what the site says.</p>' + rule + '<button class="btn pol" id="boxStart">Begin the case</button>';
else if (bx.status === 'started') { h = head('\u{1F50E} On the case: ' + esc(bx.site)) + '<p>Stay on the site tab for at least ' + bx.dwell + ' seconds and read what it says. A note on the page tells you when your visit is recorded. Your question appears here right after.</p><p><a href="' + esc(bx.url || '#') + '" target="_blank" rel="noopener">Open the site again ↗</a> <span class="box-dim">· if the note never showed, press Begin again after this attempt times out.</span></p>' + (bx.expires && Date.now() > bx.expires ? '<button class="btn" id="boxStart">Begin again</button>' : ''); boxPoll = setTimeout(boxRefresh, 6000); }
else if (bx.status === 'visited') h = head('\u{1F50E} Your question: ' + esc(bx.site)) + '<p class="box-q">' + esc(bx.question) + '</p><div class="box-opts">' + (bx.options || []).map((o, i) => '<label class="box-opt"><input type="radio" name="boxAns" value="' + i + '"> <span>' + esc(o) + '</span></label>').join('') + '</div>' + rule + '<button class="btn pol" id="boxAnswer" disabled>Lock in my answer</button> <a class="box-dim" href="' + esc(bx.url || '#') + '" target="_blank" rel="noopener">Look at the site again ↗</a>';
else if (bx.status === 'won') h = head('✅ Case solved') + '<p>You got it right: <b>' + pol + '</b> is yours. <span class="box-dim">' + esc(bx.question) + ' ' + esc(bx.answer) + '.</span></p><p class="box-dim">A new box unlocks tomorrow when you finish your hunts.</p>';
else if (bx.status === 'missed') h = head('Not this time') + '<p class="box-dim">' + esc(bx.question) + ' The answer was <b>' + esc(bx.answer) + '</b>.</p><p class="box-dim">A new box unlocks tomorrow when you finish your hunts.</p>';
else if (bx.status === 'answering') { h = head('Checking your answer…'); boxPoll = setTimeout(boxRefresh, 3000); }
el.innerHTML = h; el.hidden = !h;
const o = $('boxOpen'); if (o) o.onclick = async () => { o.disabled = true; const r = await api('/api/my/box/open', {}); if (r.error) toast(esc(r.error), 'bad'); await load(); };
const s = $('boxStart'); if (s) s.onclick = async () => { s.disabled = true; const r = await api('/api/my/box/start', {}); if (r.error) { toast(esc(r.error), 'bad'); s.disabled = false; return; } window.open(r.url, '_blank', 'noopener'); await load(); };
const a = $('boxAnswer');
if (a) {
el.querySelectorAll('input[name=boxAns]').forEach(x => x.addEventListener('change', () => { a.disabled = false; }));
a.onclick = async () => {
const pick = el.querySelector('input[name=boxAns]:checked'); if (!pick) return;
a.disabled = true; el.querySelectorAll('input[name=boxAns]').forEach(x => { x.disabled = true; });
const r = await api('/api/my/box/answer', { choice: Number(pick.value) });
if (r.error) { toast(esc(r.error), 'bad'); await load(); return; }
toast(r.correct ? '\u{1F50E} <b>Case solved!</b> ' + esc(r.message.replace(/^Case solved\.\s*/, '')) : esc(r.message), r.correct ? 'big' : '');
if (r.unlocked && r.unlocked.length) { const id = r.unlocked[0]; setTimeout(async () => { await load(); shareBadge(id, true); }, 1200); } else await load();
};
}
}
let explorer = 'https://polygonscan.com';
async function load() { board = await api('/api/my/board'); render(); }
async function start(id) {