Files
instantadpay/public/assets/game-strip.js
T

37 lines
3.5 KiB
JavaScript

/* InstantAdPay "More games" strip (2026-10-03). Served by instantadpay.com and loaded by every network game, so the list
of games lives in one place (/api/public/games: live games, Spooky Doors only while its season runs). Each card goes
through /g/<slug>?from=<this game>, which counts the hop and lands a signed-in member straight in the game.
Theme with CSS variables on the container (--gs-*). Usage:
IAPGames.strip(el, { current: 'driprunner', title: 'More games' }); */
(function () {
var IAP = 'https://instantadpay.com';
try { var me = document.currentScript && document.currentScript.src; if (me) IAP = new URL(me).origin; } catch (e) {}
var CSS = '.iapgs{--ink:var(--gs-ink,#f2efff);--mu:var(--gs-muted,#b7b0d6);--card:var(--gs-card,rgba(255,255,255,.06));--ln:var(--gs-line,rgba(255,255,255,.16));--hot:var(--gs-hot,#ff8a1f);color:var(--ink);font-family:var(--gs-font,inherit);text-align:left}'
+ '.iapgs .gs-h{font-size:12px;font-weight:800;letter-spacing:.14em;text-transform:uppercase;color:var(--mu);margin:0 0 8px}'
+ '.iapgs .gs-row{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(150px,1fr);gap:10px;overflow-x:auto;scroll-snap-type:x mandatory;padding-bottom:4px;-webkit-overflow-scrolling:touch}'
+ '.iapgs a.gs-c{scroll-snap-align:start;display:flex;flex-direction:column;text-decoration:none;color:var(--ink);background:var(--card);border:1px solid var(--ln);border-radius:12px;overflow:hidden;min-width:0}'
+ '.iapgs a.gs-c:hover,.iapgs a.gs-c:focus-visible{border-color:var(--ink)}'
+ '.iapgs .gs-c img{display:block;width:100%;aspect-ratio:1200/630;object-fit:cover;background:#000}'
+ '.iapgs .gs-t{padding:8px 10px 10px;display:grid;gap:3px}.iapgs .gs-t b{font-size:14px;line-height:1.2}'
+ '.iapgs .gs-t small{font-size:12px;line-height:1.35;color:var(--mu)}.iapgs .gs-t em{font-style:normal;font-size:10.5px;font-weight:800;letter-spacing:.06em;text-transform:uppercase;color:var(--mu)}'
+ '.iapgs .gs-t em.hot{color:var(--hot)}';
function esc(s) { return String(s == null ? '' : s).replace(/[&<>"]/g, function (c) { return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]; }); }
var cache = null;
function list() { if (!cache) cache = fetch(IAP + '/api/public/games', { credentials: 'omit' }).then(function (r) { return r.json(); }).then(function (j) { return (j && j.games) || []; }).catch(function () { cache = null; return []; }); return cache; }
function strip(el, opt) {
if (!el) return Promise.resolve(0); opt = opt || {};
if (!document.getElementById('iapgsCss')) { var s = document.createElement('style'); s.id = 'iapgsCss'; s.textContent = CSS; document.head.appendChild(s); }
return list().then(function (games) {
var g = games.filter(function (x) { return x.slug !== opt.current; });
if (!g.length) { el.hidden = true; return 0; }
el.classList.add('iapgs'); el.hidden = false;
el.innerHTML = '<p class="gs-h">' + esc(opt.title || 'More games') + '</p><div class="gs-row">' + g.map(function (x) {
return '<a class="gs-c" href="' + IAP + '/g/' + x.slug + '?from=' + encodeURIComponent(opt.current || '') + '"><img src="' + esc(x.art) + '" alt="" loading="lazy" style="object-position:' + esc(x.artPos || 'center') + '">'
+ '<span class="gs-t"><em' + (x.seasonal ? ' class="hot"' : '') + '>' + esc(x.tag) + '</em><b>' + esc(x.name) + '</b><small>' + esc(x.line) + '</small></span></a>';
}).join('') + '</div>';
return g.length;
});
}
window.IAPGames = { strip: strip, list: list, origin: IAP };
})();