Files
instantadpay/public/assets/blog-page.js
T

20 lines
1.9 KiB
JavaScript

// public blog pages: the shared nav (with wallet status) and footer, nothing else
(function () { try { IAP.renderNav(location.pathname.indexOf('/leaderboard') === 0 ? 'leaderboard' : 'blog'); } catch (e) {} })();
// Viral links (2026-09-21): a signed-in member sees this article's address with their own ?ref= on the
// end, and the share buttons carry it too. Whoever opens it is tagged to them like an invite link.
(async function () {
try {
const share = document.querySelector('p.share'); if (!share) return;
const me = await (await fetch('/api/me')).json();
const tok = me && me.signedIn && (me.username || me.refCode); if (!tok) return;
const link = 'https://instantadpay.com' + location.pathname + '?ref=' + encodeURIComponent(tok);
share.querySelectorAll('a').forEach(a => { a.href = a.href.replace(encodeURIComponent('https://instantadpay.com' + location.pathname), encodeURIComponent(link)); });
const bar = document.createElement('div');
bar.id = 'viralBar';
bar.style.cssText = 'margin-top:18px;padding:12px 14px;border:1px solid var(--line);border-radius:12px;background:var(--card, rgba(255,255,255,.03));display:flex;gap:10px;align-items:center;flex-wrap:wrap';
bar.innerHTML = '<div style="flex:1;min-width:220px"><div class="eyebrow" style="margin:0 0 4px">Your link for this article</div><div class="mono small" style="overflow-wrap:anywhere">' + link.replace(/[&<>]/g, '') + '</div><div class="muted small" style="margin-top:4px">Share this and anyone who joins from it is yours, same as your invite link.</div></div><button class="btn small" type="button">Copy link</button>';
bar.querySelector('button').onclick = async () => { try { await navigator.clipboard.writeText(link); IAP.status('Link copied.', 'ok'); } catch (e) { IAP.status('Copy failed.', 'bad'); } };
share.parentNode.insertBefore(bar, share);
} catch (e) {}
})();