Invite friends card in the lobby + ?ref attribution on every entry page

Marty: members could not find their referral link. A signed-in player now sees an
"Invite friends" card right under Play: their /r/<username> link (previews with their
own card), Copy (clipboard API, select+copy fallback, prompt last) with a Copied!
confirmation, and Share where the phone has a share sheet. Link stats and the how-it-works
line moved into the card. No username yet: the card says how to get one.

Attribution: ?ref=<name> on /, /play and /signin (and ?r= on the landing, where framed
/r/<name> lands) now sets the same dr.ref sponsor cookie as /r/<name>, last touch wins.
/r/<name> for a name the game does not know keeps it as /?ref=<name> instead of
dropping it. signin.js also reads ?ref straight from the URL. Tests cover each path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-05 07:25:22 -05:00
parent 09692de8c6
commit 11d6f46950
6 changed files with 71 additions and 11 deletions
+20 -3
View File
@@ -71,9 +71,11 @@ function lobby() {
$('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;
// the invite card shows for every signed-in player; without a username there is no link yet, so it says how to get one
$('lShare').hidden = false; $('invHas').hidden = !ME_EXTRA.share; $('invNone').hidden = !!ME_EXTRA.share; $('invNoneGo').href = IAP + '/my';
$('invLink').value = ME_EXTRA.share || ''; $('bShare').hidden = !navigator.share;
$('lShareHow').innerHTML = 'Players whose InstantAdPay sponsor is you are your team. Each time one of them refuels, ' + (rf.pct || 10) + '% of what that refuel adds to the pool is credited to your balance, and it is sent to your wallet with your drips at ' + Number((BAL && BAL.threshold) || 0.25).toFixed(2) + ' POL. <a href="/#team" target="_blank" rel="noopener">How it works</a>';
$('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)';
$('lShareStat').innerHTML = 'Your link: <b>' + (rf.clicks || 0) + '</b> visit' + (rf.clicks === 1 ? '' : 's') + ' · <b>' + (rf.count || 0) + '</b> player' + (rf.count === 1 ? '' : 's') + ' on your team · <b>' + f3(rf.earned) + '</b> POL earned from their refuels (' + (rf.pct || 0) + '% of each)';
}
show('ovLobby');
}
@@ -167,7 +169,22 @@ function starterOffer(o) {
$('cOfferNo').addEventListener('click', function () { $('cOffer').hidden = true; });
$('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:'); });
$('bShare').addEventListener('click', function () { share('Come play Drip Runner with me. Hop the network, dodge the bots:'); });
// Copy: the clipboard API where the page may use it, else select the field and copy, else a prompt to copy by hand
var copyT = null;
function copied(ok) {
var b = $('bCopy'); clearTimeout(copyT);
if (!ok) { window.prompt('Copy your invite link', ME_EXTRA.share); return; }
b.textContent = 'Copied!'; b.classList.add('done'); toast('Invite link copied. Paste it anywhere.');
copyT = setTimeout(function () { b.textContent = 'Copy link'; b.classList.remove('done'); }, 2200);
}
function copyFallback() { var f = $('invLink'), ok = false; try { f.focus(); f.select(); f.setSelectionRange(0, f.value.length); ok = document.execCommand('copy'); } catch (e) { ok = false; } f.blur(); copied(ok); }
$('bCopy').addEventListener('click', function () {
var url = ME_EXTRA.share; if (!url) return;
if (navigator.clipboard && navigator.clipboard.writeText && window.isSecureContext !== false) navigator.clipboard.writeText(url).then(function () { copied(true); }, copyFallback);
else copyFallback();
});
$('invLink').addEventListener('focus', function () { this.select(); });
$('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); }); });