Files
instantadpay/public/assets/refuel.js
T

66 lines
6.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* Drip Runner refuel: one verified visit, then back to the game 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 run (Marty, 2026-09-30)
var gameHome = tokRet ? tokRet.split('?')[0] : 'https://driprunner.saasy.top/play';
var GAME = 'Drip Runner', inGame = false; try { inGame = window.parent !== window; } catch (e) { inGame = true; } // Gem Kingdom shows this page in an overlay (2026-10-03)
function setGame(r) { if (!r || !r.game) return; GAME = r.game; var bar = document.querySelector('.rf-bar span'); if (bar) bar.innerHTML = 'InstantAdPay \u00b7 <b>verified visit</b> \u00b7 ' + (r.label || 'refuel') + ' for ' + esc(GAME); }
var ret = null, dwell = 8, left = 8, timer = null, done = false;
function msg(title, text, backUrl) { $('rfFrame').innerHTML = '<div class="rf-msg" style="background:#0b1020;height:100%"><h1>' + title + '</h1><p>' + text + '</p></div>'; $('rfDone').hidden = true; $('rfCheck').hidden = true; var b = $('rfBack'); b.hidden = false; var to = backUrl || gameHome; b.textContent = backUrl ? 'Back to the game' : 'Back to Drip Runner'; b.onclick = function () { location.href = to; }; }
function esc(s) { return String(s == null ? '' : s).replace(/[&<>"']/g, function (c) { return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]; }); }
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() { $('rfN').textContent = left; $('rfRing').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('rfVideo'); if (vid && (vid.paused || vid.ended && left > 1)) return; // a video must actually be playing
left--; if (left > 0) return ring();
clearInterval(timer); ring(); $('rfHint').textContent = 'One quick check to count the visit:';
challenge();
}
function challenge() {
api('/api/refuel/challenge?n=' + encodeURIComponent(nonce)).then(function (c) {
if (c.early) { setTimeout(challenge, (c.wait || 1) * 1000 + 300); return; }
if (c.error) { $('rfHint').textContent = c.error; return; }
$('rfPrompt').textContent = 'Tap the ' + c.prompt + ':'; var w = $('rfOpts'); w.innerHTML = '';
c.options.forEach(function (em, i) { var b = document.createElement('button'); b.type = 'button'; b.textContent = em; b.addEventListener('click', function () { answer(i); }); w.appendChild(b); });
$('rfCheck').hidden = false;
});
}
function answer(i) {
api('/api/refuel/done', { n: nonce, answer: i }).then(function (r) {
if (r.error) { if (r.retry) return challenge(); $('rfHint').textContent = r.error; $('rfCheck').hidden = true; return; }
done = true; $('rfCheck').hidden = true; var gk = GAME === 'Gem Kingdom';
$('rfHint').textContent = gk ? 'Visit counted. Your heroes are back on their feet.' : 'Visit counted. Your tank is full.';
if (gk && inGame) { try { window.parent.postMessage({ gkContinue: nonce, ok: true }, '*'); } catch (e) {} }
var b = $('rfDone'); b.disabled = false; b.textContent = gk ? 'Back to the battle' : 'Back to the run'; b.onclick = function () { location.href = r.ret; };
setTimeout(function () { location.href = r.ret; }, 1200);
});
}
if (!tok) return msg('No refuel link', 'Open this page from the game’s Refuel button.');
api('/api/refuel/open?t=' + encodeURIComponent(tok)).then(function (r) {
setGame(r);
if (r.error) return msg('Refuel link problem', esc(r.error));
if (r.done) { location.href = r.ret; return; }
if (r.none) return msg(r.why === 'cap' ? 'That is today’s refuels' : 'No sponsor pages right now', r.why === 'cap' ? 'You have used today’s refuels. Your run and progress are saved, and refuels reopen at midnight Central. Your regular InstantAdPay visits are not affected.' : 'You have used every sponsor page and video running right now. Try again later: new ones start all the time.', r.ret + '&none=1');
ret = r.ret; dwell = r.dwell || 8; left = Math.max(1, dwell - (r.elapsed || 0));
if (r.mode === 'video') { // no sponsor pages left: a member video ad instead
$('rfTitle').textContent = r.title || 'Member video'; $('rfUrl').textContent = 'video ad';
$('rfHint').textContent = 'You have visited every sponsor page running right now, so this refuel is a short member video. Keep it playing.';
var v = document.createElement('video'); v.id = 'rfVideo'; 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';
$('rfFrame').innerHTML = ''; $('rfFrame').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(); }; $('rfFrame').appendChild(un);
v.play().catch(function () { $('rfHint').textContent = 'Tap the video to start it. The timer runs while it plays.'; v.onclick = function () { v.play(); }; });
ring(); timer = setInterval(tick, 1000); return;
}
$('rfTitle').textContent = r.title || 'Member site'; try { $('rfUrl').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'); $('rfFrame').innerHTML = ''; $('rfFrame').appendChild(f);
var o = $('rfOpen'); o.href = r.target; o.hidden = false;
ring(); timer = setInterval(tick, 1000);
}).catch(function () { msg('Could not load the visit', 'Check your connection and go back to the game.'); });
})();