/* Spooky Doors door: one verified visit (a member's page or ad), then back to the street with a signed receipt. */ (function () { 'use strict'; var $ = function (id) { return document.getElementById(id); }; var q = new URLSearchParams(location.search); var tok = q.get('t') || ''; var nonce = '', tokRet = '', game = 'spookydoors'; try { var claims = JSON.parse(atob(tok.split('.')[0].replace(/-/g, '+').replace(/_/g, '/'))); nonce = claims.nonce || ''; tokRet = claims.ret || ''; if (claims.game === 'roadagent') game = 'roadagent'; } catch (e) {} // Road Agent (2026-10-07) uses the same door as a fuel stop; the words change, the round trip does not var RA = game === 'roadagent'; var W = RA ? { back: 'Back to the highway', unit: 'Fuel stop', name: 'Road Agent', home: 'https://roadagent.app/play', open: 'Open this page from a fuel stop in Road Agent.', waiting: 'Pulling into the fuel stop…', treat: ' has fuel for you.', treatSomeone: 'Visit counted. Fuel loaded.', house: 'A house ad: a smaller fuel bonus while the sponsors’ ads are resting. Stay on this page.', capTitle: 'That is tonight’s fuel stops', cap: 'You have used every fuel stop for today. Your scrap is safe, and the pumps open again at midnight Central.', none: 'This stop is closed: there are no sponsor pages or videos left for you right now. No fuel here, and this stop does not count. Head back and try again later.', noneTitle: 'Pumps are closed' } : { back: 'Back to the street', unit: 'Door', name: 'Spooky Doors', home: 'https://spookydoors.com/play', open: 'Open this page by knocking on a door in Spooky Doors.', waiting: 'Someone is coming to the door…', treat: ' has a treat for you.', treatSomeone: 'Visit counted. Someone has a treat for you.', house: 'A house ad: a smaller treat while the street’s ads are resting. Stay on this page.', capTitle: 'That is tonight’s doors', cap: 'You have knocked on every door for today. Your candy is safe, and the doors open again at midnight Central.', none: 'The lights are out at this house: there are no member pages or videos left for you right now. No candy here, and this door does not count. Head back and try the next house.', noneTitle: 'Nobody’s home' }; if (RA) { document.body.classList.add('ra'); var bb0 = document.getElementById('sdBrand'); if (bb0) bb0.textContent = W.name; var t0 = document.getElementById('sdTitle'); if (t0) t0.textContent = W.waiting; document.title = 'Fuel stop · Road Agent verified visit'; var kk = document.querySelector('#sdFrame h1'); if (kk) { kk.textContent = 'Fuel stop'; kk.nextElementSibling.textContent = 'Pulling in...'; } } // every dead end on this page keeps a way back to the street var gameHome = tokRet ? tokRet.split('?')[0] : W.home; var dwell = 8, left = 8, timer = null; function esc(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]; }); } function msg(title, text, backUrl, auto) { $('sdFrame').innerHTML = '

' + esc(title) + '

' + esc(text) + '

'; $('sdDone').hidden = true; $('sdCheck').hidden = true; $('sdRow').hidden = true; var b = $('sdBack'); b.hidden = false; var to = backUrl || gameHome; b.textContent = W.back; b.onclick = function () { location.href = to; }; if (auto && backUrl) setTimeout(function () { location.href = backUrl; }, 2500); } function api(p, body) { return fetch(p, body ? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) } : {}).then(function (r) { return r.json(); }); } function ring() { $('sdN').textContent = left; $('sdRing').style.setProperty('--p', ((dwell - left) / dwell * 100) + '%'); } function tick() { if (document.hidden) return; // the timer only runs while the page is in front var vid = document.getElementById('sdVideo'); if (vid && (vid.paused || vid.ended && left > 1)) return; // a video must actually be playing left--; if (left > 0) return ring(); clearInterval(timer); ring(); $('sdHint').textContent = 'One quick check to count the visit:'; challenge(); } function challenge() { api('/api/door/challenge?n=' + encodeURIComponent(nonce)).then(function (c) { if (c.early) { setTimeout(challenge, (c.wait || 1) * 1000 + 300); return; } if (c.error) { $('sdHint').textContent = c.error; return; } $('sdPrompt').textContent = 'Tap the ' + c.prompt + ':'; var w = $('sdOpts'); w.innerHTML = ''; c.options.forEach(function (em, i) { var b = document.createElement('button'); b.type = 'button'; b.textContent = em; b.setAttribute('aria-label', 'Option ' + (i + 1)); b.addEventListener('click', function () { answer(i); }); w.appendChild(b); }); $('sdCheck').hidden = false; }); } function answer(i) { api('/api/door/done', { n: nonce, answer: i }).then(function (r) { if (r.error) { if (r.retry) return challenge(); if (r.cap && r.ret) return msg(W.capTitle, W.cap, r.ret, true); $('sdHint').textContent = r.error; $('sdCheck').hidden = true; var bb = $('sdBack'); bb.hidden = false; bb.onclick = function () { location.href = gameHome; }; return; } $('sdCheck').hidden = true; $('sdHint').textContent = r.golden ? 'Visit counted. Golden Door! ' + (r.host ? '@' + r.host + ' has' : 'Someone has') + ' a treat for you, plus ' + (r.bonus || 0) + ' bonus candy.' : r.house ? 'Visit counted. A smaller treat from ' + (r.program || 'the house') + ' is on its way.' : r.host ? 'Visit counted. @' + r.host + W.treat : W.treatSomeone; var b = $('sdDone'); b.disabled = false; b.textContent = W.back; b.onclick = function () { location.href = r.ret; }; setTimeout(function () { location.href = r.ret; }, 1200); }); } if (!tok) return msg(RA ? 'No fuel stop here' : 'No door here', W.open); api('/api/door/open?t=' + encodeURIComponent(tok)).then(function (r) { if (r.error) return msg('Door link problem', r.error); if (r.done) { location.href = r.ret; return; } if (r.none) return r.why === 'cap' ? msg(W.capTitle, W.cap + ' Your regular InstantAdPay visits are not affected.', r.ret, true) : msg(W.noneTitle, W.none, r.ret, true); dwell = r.dwell || 8; left = Math.max(1, dwell - (r.elapsed || 0)); if (r.doors && r.doors.cap) { var ch = $('sdDoors'); ch.textContent = W.unit + ' ' + Math.min(r.doors.cap, (r.doors.used || 0) + 1) + ' of ' + r.doors.cap; ch.hidden = false; } var who = r.house ? 'House ad' : r.host ? '@' + r.host + (RA ? '’s stop' : '’s door') : (RA ? 'A sponsor’s stop' : 'A member’s door'); if (r.golden) { document.body.classList.add('gold'); $('sdGold').hidden = false; who = 'Golden Door! ' + who; } // gold variant: bonus candy on this one if (r.mode === 'video') { // no member pages left: a member video ad instead $('sdTitle').textContent = who + ': ' + (r.title || 'member video'); $('sdUrl').textContent = 'video ad'; $('sdHint').textContent = 'You have visited every member page running right now, so this ' + (RA ? 'stop' : 'door') + ' is a short member video. Keep it playing.'; var v = document.createElement('video'); v.id = 'sdVideo'; v.src = r.video.url; v.autoplay = true; v.muted = true; v.playsInline = true; v.setAttribute('playsinline', ''); v.loop = true; v.controls = false; v.style.cssText = 'position:absolute;inset:0;width:100%;height:100%;object-fit:contain;background:#000'; $('sdFrame').innerHTML = ''; $('sdFrame').appendChild(v); var un = document.createElement('button'); un.type = 'button'; un.textContent = 'Tap for sound'; un.style.cssText = 'position:absolute;right:10px;bottom:10px;z-index:2;padding:8px 12px;border-radius:8px;border:0;background:rgba(0,0,0,.6);color:#fff;font:600 12px system-ui'; un.onclick = function () { v.muted = false; v.play().catch(function () {}); un.remove(); }; $('sdFrame').appendChild(un); v.play().catch(function () { $('sdHint').textContent = 'Tap the video to start it. The timer runs while it plays.'; v.onclick = function () { v.play(); }; }); ring(); timer = setInterval(tick, 1000); return; } $('sdTitle').textContent = who + ': ' + (r.title || 'member site'); try { $('sdUrl').textContent = new URL(r.target).hostname; } catch (e) {} if (r.house) $('sdHint').textContent = W.house; if (r.golden) $('sdHint').textContent = 'A Golden Door: this one comes with ' + (r.bonus || 0) + ' bonus candy. Stay on this page; the timer only runs while it is in front.'; var f = document.createElement('iframe'); f.src = r.target; f.setAttribute('referrerpolicy', 'no-referrer'); f.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-forms allow-popups'); $('sdFrame').innerHTML = ''; $('sdFrame').appendChild(f); var o = $('sdOpen'); o.href = r.target; o.hidden = false; ring(); timer = setInterval(tick, 1000); }).catch(function () { msg(RA ? 'Could not open the fuel stop' : 'Could not open the door', RA ? 'Check your connection and go back to the highway.' : 'Check your connection and go back to the street.'); }); })();