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(); });
+3 -2
View File
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Your board · PolHunter</title>
<meta name="robots" content="noindex">
<link rel="stylesheet" href="/style.css?v=17">
<link rel="stylesheet" href="/style.css?v=18">
</head>
<body>
<div class="wrap">
@@ -19,6 +19,7 @@
<h2>Your missions</h2>
<div class="sub" id="rangeLine">Each find pays a random drip. Your codes are yours alone.</div>
<div id="refSlot"></div>
<div id="boxSlot" class="box-card" hidden></div>
<div id="fbank" hidden style="margin:12px 0 16px;padding:14px 16px;border-radius:16px;border:1px solid var(--edge-hi);background:rgba(130,71,229,.12)"></div>
<div class="grid" id="missions"><div class="card"><p>Loading your board…</p></div></div>
</section>
@@ -48,6 +49,6 @@
<footer class="foot">Rewards are for completed missions, not income. The daily pool is limited; when it is spent, claims close until midnight Central. Cryptocurrency involves risk of loss.</footer>
</div>
<div class="modal" id="shareModal" hidden><div class="modal-card"><button class="modal-x" id="shareClose" type="button" aria-label="Close">×</button><div id="shareBody"></div></div></div>
<script src="/app.js?v=19"></script>
<script src="/app.js?v=20"></script>
</body>
</html>
+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) {
Binary file not shown.

After

Width:  |  Height:  |  Size: 213 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 234 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 KiB

+9
View File
@@ -36,12 +36,21 @@
box.addEventListener('click', function () { var done = function () { var s = box.querySelector('[data-ph-hint]'); if (s) s.textContent = 'copied, paste it on your board'; }; try { navigator.clipboard.writeText(code).then(done, done); } catch (e) { done(); } });
el.appendChild(box);
}
function note(slot) {
var el = slotEl(slot); el.innerHTML = '';
var box = document.createElement('div'); box.setAttribute('role', 'note');
box.style.cssText = 'display:inline-flex;align-items:center;gap:10px;padding:12px 14px;border-radius:14px;background:linear-gradient(135deg,#1a0f3d,#2b1a63);color:#f1eefb;font:600 13px/1.35 system-ui,-apple-system,"Segoe UI",sans-serif;box-shadow:0 8px 30px rgba(130,71,229,.45),0 0 0 1px rgba(255,255,255,.08);max-width:100%';
box.innerHTML = '<img src="' + API + '/img/coin-sm.png" alt="" width="26" height="26" style="width:26px;height:26px;object-fit:contain;flex:none"><span><span style="color:#f3be43">Ad Detective: visit recorded.</span><br><span style="font-weight:500;opacity:.85">Look around this page, then answer your question on your PolHunter board.</span></span>';
el.appendChild(box);
}
var tries = 0, pending = null, done = false;
// phones freeze a background tab's timers: when the hunter comes back to this tab, ask right away
document.addEventListener('visibilitychange', function () { if (document.visibilityState === 'visible' && !done) { clearTimeout(pending); ask(); } });
function ask() {
tries++; if (tries > 80 || done) return;
fetch(API + '/api/embed/code?t=' + encodeURIComponent(t), { mode: 'cors', credentials: 'omit' }).then(function (r) { return r.json(); }).then(function (r) {
// an Ad Detective case: no code, just the receipt; the question is waiting on the hunter's board
if (r && r.visited) { done = true; note(Number(r.slot) % slots); try { sessionStorage.removeItem('ph.token'); } catch (e) {} return; }
if (r && r.code) { done = true; render(r.code, Number(r.slot) % slots); try { sessionStorage.removeItem('ph.token'); } catch (e) {} return; }
if (r && r.wait) { pending = setTimeout(ask, Math.min(r.wait, 5) * 1000); return; }
// expired / gone / wrong origin: say nothing
+13
View File
@@ -141,3 +141,16 @@ textarea{width:100%;padding:12px 14px;border-radius:12px;border:1px solid var(--
/* the one condition that decides whether a referral ever pays, said plainly on the card itself
rather than discovered when the bounty does not arrive (Marty, 2026-09-23) */
.ref-note{margin-top:8px;font-size:12.5px;line-height:1.45;color:var(--dim)}
/* Mystery Hunt Box + Ad Detective (2026-09-26) */
.box-card{margin:12px 0 16px;padding:16px 18px;border-radius:16px;border:1px solid rgba(243,190,67,.45);background:linear-gradient(135deg,rgba(243,190,67,.10),rgba(130,71,229,.14))}
.box-card h3{margin:4px 0 8px;font-size:18px}
.box-card p{margin:0 0 10px;line-height:1.5}
.box-hd{font:700 12px var(--font);letter-spacing:.12em;text-transform:uppercase;color:var(--gold)}
.box-dim{color:var(--muted);font-size:13px}
.box-rule{font-weight:700;color:var(--gold);font-size:14px}
.box-q{font-size:17px;font-weight:700}
.box-opts{display:grid;gap:8px;margin:0 0 12px}
.box-opt{display:flex;align-items:flex-start;gap:10px;padding:10px 12px;border-radius:12px;border:1px solid var(--edge);background:rgba(0,0,0,.25);cursor:pointer;line-height:1.4}
.box-opt:has(input:checked){border-color:var(--gold);background:rgba(243,190,67,.12)}
.box-opt input{margin-top:3px;accent-color:#f3be43}