Login ad in the games: the sponsor interstitial after a fresh in-game sign-in, counted per surface
- Game sign-in kit (game-signin.js): after a fresh email sign-in (never a remembered pass) the kit shows the login ad before the hand-off to /auth?t=, same as the dashboard: sponsor card, Open Ad (a counted click through /api/ads/click), sponsor framed in a full-screen overlay when frameable else a new tab, 10 s countdown (loginDwellSeconds), then Continue to the game. No ad, an error, a non-200 or a 7 s stall all go straight to the game. A game page whose CSP blocks the frame gets a new-tab link instead. mount option loginAd: false switches it off. - GET /api/game/ads/login?game=<slug>: CORS only for that game's GAME_AUTH origins (dev: localhost); the dashboard /api/ads/slot route keeps no CORS. Both share loginAdFor() (ads.serve: impression + lastShownDay as before). Drip Runner and PolyBreak are marked frames: false (their CSP is default-src 'self'), so their ad opens in a new tab; frame checks for games ignore an instantadpay.com-only frame-ancestors allowance. - loginshows.js: every login-ad request tallied per Central day, surface (dashboard or game slug) and kind (member slot, house, none); MySQL table login_shows (created on first use) or DATA_DIR/login-shows.json. GET /api/admin/login-shows + a Login-ad showings card on the admin Traffic pane (dashboard vs games, house, no-ad, by game). - The kit is served no-cache so games pick it up without a tag bump; admin.js tag bumped. - Chatbot fact updated (slot rules + games), KNOWLEDGE_DATE 2026-10-18. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
from the player's browser; the game only ever receives its normal hand-off token, which it opens at /auth.
|
||||
Host page sets theme through CSS variables on .iapsi (--si-*). Usage:
|
||||
IAPSignin.mount(el, { game: 'driprunner', ref: 'skycash', oneTap: 'https://instantadpay.com/api/my/driprunner' });
|
||||
IAPSignin.enter('wallet'); // nudge: opens InstantAdPay in a new tab, already signed in */
|
||||
IAPSignin.enter('wallet'); // nudge: opens InstantAdPay in a new tab, already signed in
|
||||
After a fresh sign-in (never on a remembered pass) the kit shows the InstantAdPay login ad before the hand-off,
|
||||
same as the dashboard: sponsor card, Open Ad (a counted click), 10 s countdown, then Continue. Any ad error,
|
||||
or no ad to show, goes straight to the game. mount option loginAd: false switches it off (2026-10-18). */
|
||||
(function () {
|
||||
var IAP = 'https://instantadpay.com';
|
||||
try { var me = document.currentScript && document.currentScript.src; if (me) IAP = new URL(me).origin; } catch (e) {}
|
||||
@@ -27,9 +30,83 @@
|
||||
+ '.iapsi .lk{background:none;border:0;padding:0;font:inherit;font-size:13.5px;color:var(--mu);text-decoration:underline;cursor:pointer}.iapsi .lk[disabled]{opacity:.5;cursor:default;text-decoration:none}'
|
||||
+ '.iapsi form{display:grid;gap:12px;margin:0}.iapsi .row{display:flex;gap:14px;flex-wrap:wrap;justify-content:space-between}.iapsi label.ck{display:flex!important;gap:10px;align-items:flex-start;font-size:13px;color:var(--mu);margin:0}.iapsi .ck input{margin:3px 0 0;width:auto!important;flex:0 0 auto;height:auto;padding:0}.iapsi .ck span{flex:1}.iapsi .err:empty{display:none}'
|
||||
+ '.iapsi .err{color:var(--si-bad,#ff8a8a);font-size:14px;min-height:1px}.iapsi .fine{font-size:12px;color:var(--mu)}.iapsi .fine a{color:var(--mu)}'
|
||||
+ '.iapsi .hp{position:absolute;left:-9999px;width:1px;height:1px;opacity:0}.iapsi .chal{display:flex;gap:8px;flex-wrap:wrap}.iapsi .chal button{font-size:26px;width:52px;height:52px;border-radius:12px;border:1px solid var(--ln);background:var(--fl);cursor:pointer}';
|
||||
+ '.iapsi .hp{position:absolute;left:-9999px;width:1px;height:1px;opacity:0}.iapsi .chal{display:flex;gap:8px;flex-wrap:wrap}.iapsi .chal button{font-size:26px;width:52px;height:52px;border-radius:12px;border:1px solid var(--ln);background:var(--fl);cursor:pointer}'
|
||||
// login-ad gate (full screen, above the game page)
|
||||
+ '.iapla{position:fixed;inset:0;z-index:2147483000;display:flex;flex-direction:column;background:var(--si-ground,#0d0b1a);color:var(--si-ink,#f2efff);font-family:var(--si-font,system-ui,sans-serif)}'
|
||||
+ '.iapla-bar{display:flex;align-items:center;gap:10px 14px;flex-wrap:wrap;padding:10px 16px;background:var(--si-panel,#17142b);border-bottom:1px solid var(--si-line,rgba(255,255,255,.18))}'
|
||||
+ '.iapla-brand{font-weight:800;font-size:15px;white-space:nowrap}.iapla-brand em{color:var(--si-accent,#7c5cff);font-style:normal}.iapla-note{flex:1;min-width:140px;font-size:13px;color:var(--si-muted,#b7b0d6)}'
|
||||
+ '.iapla-timer{font-weight:700;font-size:14px;border:1px solid var(--si-line,rgba(255,255,255,.3));border-radius:999px;padding:4px 12px;white-space:nowrap}.iapla-timer.done{color:var(--si-accent,#7c5cff);border-color:var(--si-accent,#7c5cff)}'
|
||||
+ '.iapla-btn{font:inherit;font-weight:700;font-size:14px;padding:9px 14px;border:0;border-radius:10px;background:var(--si-accent,#7c5cff);color:var(--si-accent-ink,#fff);cursor:pointer;text-decoration:none;white-space:nowrap}'
|
||||
+ '.iapla-btn.sec{background:transparent;color:var(--si-ink,#f2efff);border:1px solid var(--si-line,rgba(255,255,255,.3))}.iapla-btn[disabled]{opacity:.55;cursor:default}.iapla-btn.big{font-size:17px;padding:13px 22px}'
|
||||
+ '.iapla-frame{flex:1;border:0;width:100%;background:#fff;min-height:0}.iapla-body{flex:1;display:grid;place-items:center;padding:24px 16px;overflow:auto}'
|
||||
+ '.iapla-card{max-width:560px;text-align:center;display:grid;gap:16px;justify-items:center}.iapla-card p{margin:0;font-size:14px;line-height:1.5;color:var(--si-muted,#b7b0d6)}'
|
||||
+ '.iapla-eye{font-size:12px;letter-spacing:.12em;text-transform:uppercase}.iapla-card img{max-width:100%;max-height:50vh;border-radius:12px;border:1px solid var(--si-line,rgba(255,255,255,.18))}'
|
||||
+ '.iapla-link{display:inline-block;font-size:20px;font-weight:700;color:var(--si-ink,#f2efff);background:var(--si-field,rgba(255,255,255,.06));border:1px solid var(--si-line,rgba(255,255,255,.18));border-radius:14px;padding:18px 22px}'
|
||||
+ '.iapla [hidden]{display:none!important}';
|
||||
function styleOnce() { if (document.getElementById('iapsiCss')) return; var s = document.createElement('style'); s.id = 'iapsiCss'; s.textContent = CSS; document.head.appendChild(s); }
|
||||
|
||||
// the login ad after a fresh sign-in. `then` (the hand-off) always runs exactly once: when the gate is done,
|
||||
// when there is no ad, or on any error or a slow answer, so an ad can never hold a player out of the game.
|
||||
function loginAd(game, then) {
|
||||
var over = false; function go() { if (over) return; over = true; try { then(); } catch (e) {} }
|
||||
var ctl = null; try { ctl = new AbortController(); } catch (e) {}
|
||||
var slow = setTimeout(function () { if (ctl) try { ctl.abort(); } catch (e) {} go(); }, 7000);
|
||||
fetch(IAP + '/api/game/ads/login?game=' + encodeURIComponent(game || ''), { credentials: 'omit', signal: ctl ? ctl.signal : undefined })
|
||||
.then(function (r) { return r.ok ? r.json() : {}; })
|
||||
.then(function (j) { clearTimeout(slow); if (over) return; var ad = j && j.ad; if (!ad || !ad.targetUrl) return go(); gate(ad, go); })
|
||||
.catch(function () { clearTimeout(slow); go(); });
|
||||
}
|
||||
function gate(ad, go) {
|
||||
var abs = function (u) { return /^https?:/i.test(u) ? u : IAP + u; };
|
||||
var click = abs(ad.targetUrl), site = ad.siteUrl || click, framed = !!ad.frameable, started = false, t = null;
|
||||
var g = document.createElement('div'); g.className = 'iapla'; g.setAttribute('role', 'dialog'); g.setAttribute('aria-label', 'Login sponsor');
|
||||
g.innerHTML = '<div class="iapla-bar"><span class="iapla-brand">Instant<em>AdPay</em></span>'
|
||||
+ '<span class="iapla-note" data-st>Login ad sponsor. Tap "Open Ad" to begin.</span>'
|
||||
+ '<span class="iapla-timer" data-tm hidden></span>'
|
||||
+ '<a class="iapla-btn sec" data-tab target="_blank" rel="noopener" hidden>Open site in a new tab \u2197</a>'
|
||||
+ '<button class="iapla-btn" type="button" data-go hidden>Continue to the game</button></div>'
|
||||
+ '<iframe class="iapla-frame" data-fr hidden sandbox="allow-scripts allow-same-origin allow-forms allow-popups" referrerpolicy="no-referrer" title="Sponsor site"></iframe>'
|
||||
+ '<div class="iapla-body" data-bd><div class="iapla-card"><p class="iapla-eye">Today\'s login sponsor</p>'
|
||||
+ (ad.imageUrl ? '<img src="' + esc(ad.imageUrl) + '" alt="sponsor ad">' : '<span class="iapla-link">' + esc(ad.title || 'Visit today\'s sponsor') + '</span>')
|
||||
+ '<button class="iapla-btn big" type="button" data-open>Open Ad</button>'
|
||||
+ '<p>' + (framed ? 'The sponsor\'s page opens right here under this bar. When the timer hits zero, your Continue button appears beside it.'
|
||||
: 'This sponsor\'s site opens in a new tab. The timer counts down here; come back when it hits zero to continue to the game.') + '</p></div></div>';
|
||||
var q = function (k) { return g.querySelector('[data-' + k + ']'); };
|
||||
var st = q('st'), tm = q('tm'), tab = q('tab'), btn = q('go'), fr = q('fr'), bd = q('bd'), open = q('open');
|
||||
function finish() { clearInterval(t); document.removeEventListener('securitypolicyviolation', csp); try { g.remove(); } catch (e) {} go(); }
|
||||
// a game page whose CSP refuses the frame: offer the sponsor in a new tab instead (the timer keeps running)
|
||||
function csp(ev) {
|
||||
if (!started || !framed || !/frame|child|default/.test(String(ev.violatedDirective || ev.effectiveDirective || ''))) return;
|
||||
var b = String(ev.blockedURI || '');
|
||||
fr.hidden = true; bd.hidden = true; tab.hidden = false;
|
||||
tab.href = (!b || b.indexOf(IAP) === 0) ? click : site; // blocked before our click relay ran: the tab is the counted click
|
||||
st.textContent = 'This game cannot show the sponsor here. Open it in a new tab; the timer runs here.';
|
||||
}
|
||||
document.addEventListener('securitypolicyviolation', csp);
|
||||
open.addEventListener('click', function () {
|
||||
if (started) return; started = true; open.disabled = true;
|
||||
if (framed) {
|
||||
fr.src = click; // the click relay counts it, then redirects inside the frame
|
||||
fr.hidden = false; bd.hidden = true; tab.href = site; tab.hidden = false;
|
||||
st.textContent = 'Today\'s sponsor. Have a look; your Continue button appears when the timer ends.';
|
||||
} else {
|
||||
try { window.open(click, '_blank'); } catch (e) {} // the click relay counts it
|
||||
st.textContent = 'The sponsor opened in a new tab. View it and come back; the timer runs here.';
|
||||
}
|
||||
var left = Math.max(1, Number(ad.dwell) || 10);
|
||||
tm.hidden = false; tm.textContent = 'Time remaining: ' + left + 's';
|
||||
t = setInterval(function () {
|
||||
left -= 1;
|
||||
if (left > 0) { tm.textContent = 'Time remaining: ' + left + 's'; return; }
|
||||
clearInterval(t); tm.textContent = 'Time is up'; tm.className = 'iapla-timer done';
|
||||
st.textContent = 'Thanks for the look. Your game is ready.'; btn.hidden = false;
|
||||
try { btn.focus(); } catch (e) {}
|
||||
}, 1000);
|
||||
});
|
||||
btn.addEventListener('click', finish);
|
||||
document.body.appendChild(g);
|
||||
}
|
||||
|
||||
function mount(el, opt) {
|
||||
styleOnce(); opt = opt || {};
|
||||
var game = opt.game, ref = String(opt.ref || '').toLowerCase().replace(/[^a-z0-9_]/g, '').slice(0, 40), src = String(opt.src || '').toLowerCase().replace(/[^a-z0-9_.-]/g, '').slice(0, 30);
|
||||
@@ -41,7 +118,11 @@
|
||||
function done(r) {
|
||||
if (r.pass) ls(PASS_KEY, JSON.stringify({ p: r.pass, exp: Date.now() + 29 * 86400000, email: email }));
|
||||
if (r.needUsername) return stepName(r);
|
||||
if (r.token) return onToken(r.token);
|
||||
if (r.token) { // a fresh sign-in: the login ad first (fails open to the hand-off)
|
||||
if (opt.loginAd === false) return onToken(r.token);
|
||||
el.innerHTML = '<h2>You are in</h2><p>One moment\u2026</p>';
|
||||
try { return loginAd(game, function () { onToken(r.token); }); } catch (e) { return onToken(r.token); }
|
||||
}
|
||||
err('Something went wrong. Try again.');
|
||||
}
|
||||
function stepEmail(msg) {
|
||||
|
||||
Reference in New Issue
Block a user