Referral layer: guest play from share links (/r/<username>), guest clears paid on sign-in, sharer's link via their IAP join page, 10% referrer slice of each referral refuel's pool income (IAP sponsor), share buttons + stats in the lobby and on chapter clears, wallet-less progress follows the member once a wallet is linked; 11 new checks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+37
-5
@@ -44,13 +44,31 @@ var hudCache = {}; function setHud() { if (!R) return; var v = { d: R.drips, c:
|
||||
function f3(n) { return Number(n || 0).toFixed(3); }
|
||||
|
||||
/* ---------- lobby / me ---------- */
|
||||
function loadMe() { return api('/api/me').then(function (r) { if (r._status !== 200) throw r; ME = r.me; P = r.player; BAL = r.balance; POOL = r.pool; IAP = r.iap || IAP; TIPS = r.tips || []; return r; }); }
|
||||
var ME_EXTRA = {};
|
||||
function loadMe() { return api('/api/me').then(function (r) { if (r._status !== 200) throw r; ME = r.me; P = r.player; BAL = r.balance; POOL = r.pool; IAP = r.iap || IAP; TIPS = r.tips || []; ME_EXTRA = { signin: r.signin, share: r.share, referrals: r.referrals }; return r; }); }
|
||||
// share: the phone's share sheet where there is one, else copy the link
|
||||
function share(text) {
|
||||
var url = ME_EXTRA.share; if (!url) return toast('Set a username on InstantAdPay to get a share link.');
|
||||
if (navigator.share) { navigator.share({ title: 'Drip Runner', text: text, url: url }).catch(function () {}); return; }
|
||||
var full = text + ' ' + url;
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(full).then(function () { toast('Link copied. Paste it anywhere.'); }, function () { window.prompt('Copy your link', url); });
|
||||
else window.prompt('Copy your link', url);
|
||||
}
|
||||
function lobby() {
|
||||
R = null; $('hud').classList.remove('on'); $('tapdesk').hidden = true;
|
||||
$('lChap').textContent = P.chapter; $('lDrips').textContent = P.bank.toLocaleString(); $('lPol').textContent = f3(BAL.unpaid);
|
||||
$('lPool').innerHTML = 'POL pool <b>' + f3(POOL.available) + '</b> · today’s cap left <b>' + f3(POOL.capLeft) + '</b> · a chapter drip is <b>' + f3(POOL.dripPol) + '</b>';
|
||||
$('lIap').href = IAP + '/my'; $('bLevel').href = IAP + '/my#buy'; tip('lTip');
|
||||
$('lMember').innerHTML = '<i class="' + (ME.wallet ? '' : 'no') + '"></i>InstantAdPay · ' + (ME.username ? '@' + ME.username : '#' + ME.memberId) + ' · ' + (ME.wallet ? ME.wallet.slice(0, 6) + '…' + ME.wallet.slice(-4) : 'no wallet on file');
|
||||
if (ME.guest) {
|
||||
$('lMember').innerHTML = '<i class="no"></i>Playing as a guest · sign in to keep your progress and collect POL';
|
||||
$('bSignin').hidden = false; $('bSignin').href = ME_EXTRA.signin || (IAP + '/api/my/driprunner'); $('lShare').hidden = true;
|
||||
} else {
|
||||
$('lMember').innerHTML = '<i class="' + (ME.wallet ? '' : 'no') + '"></i>InstantAdPay · ' + (ME.username ? '@' + ME.username : '#' + ME.memberId) + ' · ' + (ME.wallet ? ME.wallet.slice(0, 6) + '…' + ME.wallet.slice(-4) : 'no wallet on file');
|
||||
$('bSignin').hidden = true;
|
||||
var rf = ME_EXTRA.referrals || {};
|
||||
$('lShare').hidden = !ME_EXTRA.share;
|
||||
$('lShareStat').innerHTML = 'Your link: <b>' + (rf.clicks || 0) + '</b> visits · <b>' + (rf.count || 0) + '</b> players on your team · <b>' + f3(rf.earned) + '</b> POL earned from their refuels (' + (rf.pct || 0) + '% of each)';
|
||||
}
|
||||
show('ovLobby');
|
||||
}
|
||||
|
||||
@@ -122,13 +140,17 @@ function cleared() {
|
||||
$('cEyebrow').textContent = 'Chapter ' + c.chapter + ' cleared'; $('cTitle').textContent = 'Banked ' + (R.goal) + ' drips';
|
||||
var m = Math.floor(c.playTime / 60), s = c.playTime % 60; var tm = m + ':' + (s < 10 ? '0' : '') + s;
|
||||
$('cBig').innerHTML = '+' + f3(c.pol) + '<small>POL</small>'; $('cBig').classList.toggle('dim', !c.pol);
|
||||
var why = { paid: 'First clear, verified. Added to your game balance.', replay: c.first ? 'Verified.' : 'You cleared this one before. Only the first clear pays.', pool: 'The POL pool is empty right now. Refuel visits fill it, so this clear counts but pays nothing.', cap: 'Today’s pool cap is spent. Chapter counts, no POL today.', flagged: 'This run was flagged by the server check, so it pays nothing.' };
|
||||
var why = { paid: 'First clear, verified. Added to your game balance.', replay: c.first ? 'Verified.' : 'You cleared this one before. Only the first clear pays.', pool: 'The POL pool is empty right now. Refuel visits fill it, so this clear counts but pays nothing.', cap: 'Today’s pool cap is spent. Chapter counts, no POL today.', flagged: 'This run was flagged by the server check, so it pays nothing.', guest: 'You are playing as a guest. Sign in with InstantAdPay and this clear pays ' + f3(POOL.dripPol) + ' POL into your balance. Your progress comes with you.' };
|
||||
$('bShareClear').hidden = !!ME.guest || !ME_EXTRA.share; $('bShareClear').dataset.text = 'I just cleared Chapter ' + c.chapter + ' in Drip Runner' + (c.pol ? ' and it paid ' + f3(c.pol) + ' POL' : '') + '. Hop the network, dodge the bots:';
|
||||
$('bClearSignin').hidden = !ME.guest; if (ME.guest) $('bClearSignin').href = ME_EXTRA.signin || (IAP + '/api/my/driprunner');
|
||||
$('cText').textContent = why[c.reason] || ''; $('cChip').className = 'chip ' + (c.pol ? 'ok' : 'sig'); $('cChip').textContent = (c.pol ? 'verified' : c.reason) + ' · ' + tm + ' play time';
|
||||
R.chapter = c.next; R.goal = c.nextGoal; R.chapDrips = 0; if (r.pool != null) POOL.available = r.pool;
|
||||
tip('cTip'); setTimeout(function () { show('ovClear'); }, 500);
|
||||
});
|
||||
}
|
||||
$('bNext').addEventListener('click', function () { if (!R) return; R.paused = false; R.inv = 1.5; hideAll(); });
|
||||
$('bShareClear').addEventListener('click', function () { share(this.dataset.text || 'Play Drip Runner with me:'); });
|
||||
$('bShare').addEventListener('click', function () { share('I am playing Drip Runner, a game that pays in POL. Hop the network, dodge the bots:'); });
|
||||
$('bRestart').addEventListener('click', function () { endRun().then(newRun); });
|
||||
function endRun() { var id = R && R.id; R = null; hideAll(); return id ? api('/api/run/end', { runId: id }).catch(function () {}) : Promise.resolve(); }
|
||||
['bLobby1', 'bLobby2'].forEach(function (id) { $(id).addEventListener('click', function () { endRun().then(loadMe).then(lobby); }); });
|
||||
@@ -141,7 +163,9 @@ function snapshot(nonce) {
|
||||
try { sessionStorage.setItem('dr.snap', JSON.stringify(s)); } catch (e) {}
|
||||
}
|
||||
$('bRefuel').addEventListener('click', function () {
|
||||
if (!R) return; $('bRefuel').disabled = true;
|
||||
if (!R) return;
|
||||
if (ME.guest) { location.href = ME_EXTRA.signin || (IAP + '/api/my/driprunner'); return; } // guests sign in first; their progress follows them
|
||||
$('bRefuel').disabled = true;
|
||||
api('/api/refuel/start', { runId: R.id }).then(function (r) {
|
||||
$('bRefuel').disabled = false;
|
||||
if (r._status !== 200) return toast(r.error || 'Refuel is not available right now.');
|
||||
@@ -224,8 +248,16 @@ resize(); requestAnimationFrame(loop);
|
||||
loadMe().then(function () {
|
||||
var q = new URLSearchParams(location.search);
|
||||
if (q.get('resume')) { history.replaceState(null, '', '/play'); return tryResume(q); }
|
||||
if (q.get('collected')) { history.replaceState(null, '', '/play'); setTimeout(function () { toast('Signed in. Your guest clears paid ' + q.get('collected') + ' drip' + (q.get('collected') === '1' ? '' : 's') + ' into your balance.'); }, 600); }
|
||||
lobby();
|
||||
}).catch(function (r) {
|
||||
$('loadTitle').textContent = 'Sign in first'; $('loadText').textContent = (r && r.error) || 'Open Drip Runner from your InstantAdPay dashboard.'; var b = $('loadBtn'); b.hidden = false; b.textContent = 'Open through InstantAdPay'; b.href = (r && r.iap) || IAP + '/api/my/driprunner';
|
||||
var b = $('loadBtn'); b.hidden = false; b.href = (r && (r.signin || r.iap)) || IAP + '/api/my/driprunner';
|
||||
if (r && r.guestOk) { // came through a share or tester link: play first, sign in later
|
||||
$('loadTitle').textContent = 'Ready to run'; $('loadText').textContent = 'Play a run right now, no sign-in. Sign in with InstantAdPay when you want to keep your progress, refuel, and collect POL.';
|
||||
b.textContent = 'Sign in with InstantAdPay'; b.className = 'btn ghost'; var g = $('loadGuest'); g.hidden = false;
|
||||
g.onclick = function () { g.disabled = true; api('/api/guest', {}).then(function (x) { if (x._status !== 200) { g.disabled = false; return toast(x.error || 'Could not start a guest run.'); } return loadMe().then(function () { lobby(); newRun(); }); }); };
|
||||
return;
|
||||
}
|
||||
$('loadTitle').textContent = 'Sign in first'; $('loadText').textContent = (r && r.error) || 'Open Drip Runner from your InstantAdPay dashboard.'; b.textContent = 'Open through InstantAdPay';
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user