// The hunter's board: missions in their own order, a live timer while they are on the site, a
// code box when they are back. One open mission at a time.
(() => {
const $ = id => document.getElementById(id);
const esc = s => String(s == null ? '' : s).replace(/[&<>"]/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c]));
const api = async (path, body) => { const r = await fetch(path, body ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}); const j = await r.json().catch(() => ({})); if (r.status === 401) location.href = '/?signin=1'; return j; };
let board = null, open = null; // open: { missionId, token, url, dwell, started }
// toasts: small, stacked, gone in a few seconds
function toast(msg, kind, link) {
let host = $('toasts'); if (!host) { host = document.createElement('div'); host.id = 'toasts'; document.body.appendChild(host); }
const t = document.createElement('div'); t.className = 'toast ' + (kind || ''); t.innerHTML = msg + (link ? ' ' + esc(link.text) + '' : '');
host.appendChild(t); requestAnimationFrame(() => t.classList.add('in'));
setTimeout(() => { t.classList.remove('in'); setTimeout(() => t.remove(), 400); }, kind === 'big' ? 9000 : 6000);
}
const seenPaid = new Set(); let seenLedger = null, paidPrimed = false;
// a drip that flips to paid while the board is open gets a toast with its proof. The first pass only
// records what is already paid: history is on the ledger, not in the toasts (Marty, 2026-09-21).
function watchPaid() {
for (const d of (board.drips || [])) if (d.status === 'paid' && d.tx) {
if (paidPrimed && !seenPaid.has(d.id)) toast('\u{1F4B0} ' + d.pol + ' POL landed in your wallet.', 'ok', { href: explorer + '/tx/' + d.tx, text: 'verify \u2197' });
seenPaid.add(d.id);
}
paidPrimed = true;
}
// other hunters' finds, as they happen
async function watchLedger() {
try { const r = await (await fetch('/api/ledger')).json(); const rows = r.recent || [];
if (seenLedger) { const fresh = rows.filter(x => !seenLedger.has(x.tx)).slice(0, 2); for (const x of fresh) if (!board || !board.me || x.who !== (board.me.username ? '@' + board.me.username : '#' + board.me.memberId)) toast('\u{1F3AF} ' + esc(x.who) + ' just found ' + x.pol + ' POL on ' + esc(x.site) + '.', ''); }
seenLedger = new Set(rows.map(x => x.tx));
} catch (e) {}
}
setInterval(watchLedger, 45000); setInterval(async () => { if (board && (board.drips || []).some(d => d.status === 'due' || d.status === 'sent')) { await load(); } }, 30000);
function card(m) {
const isOpen = open && open.missionId === m.id;
const r = m.reward || {};
return '
';
}
// The best-paid thing on the board, and the reason it sits first: sharing used to live on a page
// nobody opened, so nobody shared (Marty, 2026-09-23).
function referralCard() {
const rf = board.referral; if (!rf || !rf.on) return '';
const link = (board.share && board.share.link) || '';
const today = rf.broughtToday, total = rf.brought;
const people = (rf.people || []).filter(p => p.isNew).slice(0, 5).map(p =>
'
' + esc(p.name) + '' + esc(p.state) + '
').join('');
return '
'
+ 'Best paid'
+ '
🤝 Bring a hunter
'
+ '
Send your link. When someone who has never had an InstantAdPay account joins on it, opens PolHunter and finds their first code, you get ' + rf.bountyPol + ' POL. '
+ 'After that you earn ' + rf.matchPct + '% on top of everything they find for their first ' + rf.matchDays + ' days. '
+ 'It comes out of our pool, never theirs.
'
+ '
This pays for new people only. Someone who was already a member before this mission started earns nothing, however much they hunt.
'
+ (rf.firstBonusPol ? '
\u{1F947} ' + rf.firstBonusPol + ' POL bonus, still unclaimed. It goes to the first hunter who brings someone all the way through. Nobody has yet.
' : '')
+ ''
+ '
' + today + ' brought today '
+ '· ' + total + ' all time · ' + rf.earnedPol + ' POL earned
'
+ (people ? '
' + people + '
' : '
Nobody yet. One message is all it takes.
')
+ (rf.otherSponsored ? '
' + rf.otherSponsored + ' other ' + (rf.otherSponsored === 1 ? 'member' : 'members') + ' on your InstantAdPay line ' + (rf.otherSponsored === 1 ? 'is' : 'are') + ' not counted here: they joined before this mission or came in another way, not through your PolHunter link.
' : '')
+ ''
+ '
';
}
// the explainer plays in place, the way the teaser does on the home page
function wireRefVideo() {
const b = $('refPlay'); if (!b) return;
b.addEventListener('click', () => {
const host = b.parentElement;
const v = document.createElement('video');
v.controls = true; v.autoplay = true; v.playsInline = true; v.className = 'ref-video';
v.poster = 'https://coolify-saasytop.nyc3.digitaloceanspaces.com/training/polhunter-bring-a-hunter.jpg?v=20260923a';
v.src = 'https://coolify-saasytop.nyc3.digitaloceanspaces.com/training/polhunter-bring-a-hunter.mp4?v=20260923a';
host.innerHTML = ''; host.appendChild(v);
v.play().catch(() => {});
});
}
const IAP = 'https://instantadpay.com';
function until(ms) { const s = Math.max(0, Math.round((ms - Date.now()) / 60000)); const h = Math.floor(s / 60), m = s % 60; return h ? h + 'h ' + m + 'm' : m + 'm'; }
// no wallet on the InstantAdPay account yet: the three steps, in place of the missions
function onboarding() {
return '
One thing before your first hunt. Drips are paid to the wallet on your InstantAdPay account, and yours has none yet.
'
+ '
'
+ '
Create your free InstantAdPay account. Already done: you are signed in as ' + esc(board.me.username ? '@' + board.me.username : '#' + board.me.memberId) + '.
'
+ '
Link your wallet. In your InstantAdPay dashboard open Wallet, press connect wallet and approve. Any Polygon wallet works (MetaMask, Trust, Phantom with Polygon on).
'
+ '
Come back through the door. Return to your dashboard and press Open my board again. Your missions unlock the moment a wallet is on the account.
'
+ '
';
}
// badge cards: art, lock state, share
function badgeStrip() {
const el = $('badgeStrip'); if (!el || !board.badgeCards) return;
el.innerHTML = board.badgeCards.map(b => '
' + b.icon + ' ' + esc(b.name) + '
' + esc(b.why) + '
' + (b.earned ? '' : '
\u{1F512} locked
') + '
').join('');
el.querySelectorAll('[data-share]').forEach(x => x.addEventListener('click', () => shareBadge(x.dataset.share, false)));
}
function shareBadge(id, unlocked) {
const b = (board.badgeCards || []).find(x => x.id === id); if (!b || !b.earned) return;
const text = (unlocked ? 'Achievement unlocked on PolHunter: ' : 'I earned ') + b.name + ' (' + b.why + ') on PolHunter. Visit a site, find your code, get a drip of POL to your wallet. ' + b.page;
const T = encodeURIComponent(text), U = encodeURIComponent(b.page);
$('shareBody').innerHTML = '
';
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(); }
}
// Done for the day (Marty, 2026-09-26): once a hunter has used all of today's missions, send
// them back to InstantAdPay to keep earning. Shown once per Central-time day per browser.
function doneNudge(dl) {
if (!dl || dl.left > 0 || !dl.done) return;
const day = new Date().toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
try { if (localStorage.getItem('ph.doneNudge') === day) return; localStorage.setItem('ph.doneNudge', day); } catch (e) {}
if (document.getElementById('phDone')) return;
const w = document.createElement('div');
w.id = 'phDone'; w.setAttribute('role', 'dialog'); w.setAttribute('aria-modal', 'true'); w.setAttribute('aria-labelledby', 'phDoneH');
w.style.cssText = 'position:fixed;inset:0;z-index:500;background:rgba(8,6,20,.78);display:flex;align-items:center;justify-content:center;padding:18px;backdrop-filter:blur(3px)';
w.innerHTML = '
'
+ ''
+ '
All ' + dl.done + ' missions done today
'
+ '
Nice hunting. Keep earning on InstantAdPay.
'
+ '
New missions open at midnight Central. Until then, head to InstantAdPay: open an inbox ad and watch a video to bank an extra hunt for Friday, and earn ad credits while you are there.
';
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 => '
\u{1F381} Mystery Hunt Box
' + t + '
';
const rule = '
One answer only. Look carefully before answering.
';
let h = '';
if (bx.status === 'locked') h = head('Unlocks when today’s hunts are done') + '
Find all ' + bx.need + ' of today’s codes and your box opens: a bonus case worth a fixed ' + pol + '. ' + bx.done + ' of ' + bx.need + ' found.
';
else if (bx.status === 'ready') h = head('Your box is ready') + '
Open it to see today’s bonus case. It pays a fixed ' + pol + ' and does not use up a mission.
';
else if (bx.status === 'open') h = head('\u{1F50E} Ad Detective on ' + esc(bx.site)) + '
Reward: ' + pol + ', fixed. Visit the site and look around for at least ' + bx.dwell + ' seconds. Then come back here and answer one question about what the site says.
' + rule + '';
else if (bx.status === 'started') { h = head('\u{1F50E} On the case: ' + esc(bx.site)) + '
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.
Open the site again ↗· if the note never showed, press Begin again after this attempt times out.
' + rule + ' Look at the site again ↗';
else if (bx.status === 'won') h = head('✅ Case solved') + '
You got it right: ' + pol + ' is yours. ' + esc(bx.question) + ' ' + esc(bx.answer) + '.
A new box unlocks tomorrow when you finish your hunts.
';
else if (bx.status === 'missed') h = head('Not this time') + '
' + esc(bx.question) + ' The answer was ' + esc(bx.answer) + '.
A new box unlocks tomorrow when you finish your hunts.
';
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} Case solved! ' + 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) {
const r = await api('/api/my/start', { missionId: id });
if (r.error) { toast(esc(r.error), 'bad'); if (r.spent || r.dailyDone) await load(); return; }
open = { missionId: id, token: r.token, url: r.url, dwell: r.dwell, started: Date.now(), expires: r.expires };
window.open(r.url, '_blank', 'noopener');
render();
}
function tick() {
const el = $('timer'); if (!el || !open) return;
const left = Math.max(0, open.dwell - Math.floor((Date.now() - open.started) / 1000));
el.innerHTML = left > 0 ? 'Your code appears on the site in about ' + left + 's. Stay on the site tab until it shows (switching away pauses it), then come back and paste it here.' : 'Your code should be showing on the site now. If it is not, switch to the site tab and give it a few seconds. Then paste it here.';
if (open.expires && Date.now() > open.expires) { el.innerHTML = 'This attempt timed out. Start the mission again.'; return; }
setTimeout(tick, 1000);
}
async function submit() {
const code = $('code').value.trim(); if (!code) return;
$('submit').disabled = true;
const r = await api('/api/my/submit', { token: open.token, code });
const m = $('msg'); m.className = 'msg ' + (r.error ? 'bad' : 'ok'); m.textContent = r.error || r.message;
if (!r.error && r.gamepass) board.gamepass = r.gamepass; // the Game Pass flag refreshes with every grant answer
if (!r.error && /Get the Pass/.test(r.message || '') && board.gamepass && board.gamepass.on && !board.gamepass.active) m.innerHTML = esc(r.message) + ' Get the Game Pass'; // the cap-hit nudge, in a new tab (the page may be framed)
if (r.error) toast(esc(r.error), 'bad'); else toast('\u{1F389} Found it! ' + r.pol + ' POL is on its way to your wallet.', 'big');
if (!r.error) { const a = document.createElement('a'); a.href = '#share'; a.textContent = ' Share this find \u2197'; a.style.marginLeft = '6px'; m.appendChild(a); delete $('sharetext').dataset.touched; }
// an achievement unlocked by this find: celebrate it once the board has reloaded
if (!r.error && r.unlocked && r.unlocked.length) { const id = r.unlocked[0]; toast('\u{1F3C6} Achievement unlocked!', 'big'); setTimeout(async () => { await load(); shareBadge(id, true); }, 1200); }
$('submit').disabled = false;
if (!r.error || r.spent) { open = null; setTimeout(load, 900); }
}
fetch('/api/config').then(r => r.json()).then(c => { explorer = c.explorer || explorer; }).catch(() => {});
load();
})();