a5a991d024
- Visit packs get a placement: 'all' (as before), 'doors' (Behind Spooky Doors, doorPackCost 4/door) or
'golden' (Golden Spooky Door, goldenDoorCost 6/door). campaigns.placement column (alterSafe) + JSON store.
- Doors serve golden packs first, then door packs, then the existing chain; each pack at most once per
player per Central day. Door-only packs never reach the Earn tab, refuels or the PassiveDrip listing
until rates.sdSeasonEnd ('2026-11-01'); from then on they behave as 'all'.
- Door payloads: credits = per-door price actually charged (3/4/6); Golden Doors add golden: true and
bonus: goldenBonusCandy (2) to /api/door/open, done, callback and receipt. Gold variant of /door.
- Campaign list: Spooky Doors / Golden Door chip, doors opened + unique players, Buy more doors at the
door price. Composer: placement choice with live cost. Admin rates labels + house pack placement.
- Promo tools: Spooky Doors card (spookydoors.com/r/<username>, copy, share image, two posts) on the same
season window as the Games card (seasonState helper).
- Season start moved up to 2026-10-04 (Games card + promo card + chatbot).
- qa/door.mjs covers all of the above.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
77 lines
7.3 KiB
JavaScript
77 lines
7.3 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.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 + ' 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.house ? 'House ad' : r.host ? '@' + r.host + '’s door' : '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 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 = 'A house ad: a smaller treat while the street’s ads are resting. Stay on this page.';
|
||
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('Could not open the door', 'Check your connection and go back to the street.'); });
|
||
})();
|