27c9d51fde
- SD_SSO_SECRET / SD_URL (default https://spookydoors.com); sdMint/sdOpen same token shape as Drip Runner - GET /api/my/spookydoors sign-in hand-off (?ref pass-through; iap.return spookydoors + sdshop whitelisted) - /door page (Halloween copy of /refuel, door art backdrop) + /api/door/open|challenge|done as visit kind 'door'; signed callback to SD_URL/api/door/callback (X-SD-Ts/X-SD-Sig) + 24 h door-receipt on ret&ok=1&r=; ret&none=1 when nothing to serve, ret&cap=1 at the daily cap; host = campaign owner's username - /sd/shop (+ topup/resume/confirm) costume checkout via ads.gamePurchase('Spooky Doors: <label>'), sd-receipt - Games tab: generic season window (Central days, admin preview before start, hidden after end) + pink limited-time ribbon; progress from SD_URL/api/partner/player (signed); my.js ?v bumped - Chatbot canned answer + prompt facts; qa/door.mjs (bash qa/run.sh door) end-to-end on a throwaway local copy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
74 lines
6.6 KiB
JavaScript
74 lines
6.6 KiB
JavaScript
/* 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 = ''; try { var claims = JSON.parse(atob(tok.split('.')[0].replace(/-/g, '+').replace(/_/g, '/'))); nonce = claims.nonce || ''; tokRet = claims.ret || ''; } catch (e) {}
|
||
// every dead end on this page keeps a way back to the street
|
||
var gameHome = tokRet ? tokRet.split('?')[0] : 'https://spookydoors.com/play';
|
||
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 = '<div class="dr-msg"><div class="in"><h1>' + esc(title) + '</h1><p>' + esc(text) + '</p></div></div>';
|
||
$('sdDone').hidden = true; $('sdCheck').hidden = true; $('sdRow').hidden = true;
|
||
var b = $('sdBack'); b.hidden = false; var to = backUrl || gameHome; b.textContent = 'Back to the street'; 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('That is tonight’s doors', 'You have knocked on every door for today. Your candy is safe, and the doors open again at midnight Central.', 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.host ? 'Visit counted. @' + r.host + ' has a treat for you.' : 'Visit counted. Someone has a treat for you.';
|
||
var b = $('sdDone'); b.disabled = false; b.textContent = 'Back to the street'; b.onclick = function () { location.href = r.ret; };
|
||
setTimeout(function () { location.href = r.ret; }, 1200);
|
||
});
|
||
}
|
||
if (!tok) return msg('No door here', 'Open this page by knocking on a door in Spooky Doors.');
|
||
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('That is tonight’s doors', 'You have knocked on every door for today. Your candy is safe, and the doors open again at midnight Central. Your regular InstantAdPay visits are not affected.', r.ret, true)
|
||
: msg('Nobody’s home', '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.', 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 = 'Door ' + Math.min(r.doors.cap, (r.doors.used || 0) + 1) + ' of ' + r.doors.cap; ch.hidden = false; }
|
||
var who = r.host ? '@' + r.host + '’s door' : 'A member’s door';
|
||
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 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) {}
|
||
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('Could not open the door', 'Check your connection and go back to the street.'); });
|
||
})();
|