Viral link builder: dropdown only (the paste box only ever accepted the site's own pages, which the dropdown already lists)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-09-21 06:13:25 -05:00
parent 269247c871
commit e5cbecbdb2
2 changed files with 8 additions and 20 deletions
+5 -14
View File
@@ -203,21 +203,13 @@ window.IAPPromo = (function () {
if (vp && token && vp.dataset.filled !== token) {
vp.dataset.filled = token;
const origin = 'https://instantadpay.com', enc = encodeURIComponent;
const build = raw => {
let s = String(raw || '').trim(); if (!s) return '';
if (!/^https?:\/\//i.test(s)) s = origin + (s.charAt(0) === '/' ? '' : '/') + s;
let x; try { x = new URL(s); } catch (e) { return ''; }
if (!/(^|\.)instantadpay\.com$/i.test(x.hostname) || /^\/(join|from|api|admin)(\/|$)/.test(x.pathname)) return '';
x.searchParams.delete('ref'); x.searchParams.set('ref', token);
return origin + x.pathname + x.search;
};
const build = path => { if (!path) return ''; let x; try { x = new URL(origin + path); } catch (e) { return ''; } x.searchParams.set('ref', token); return origin + x.pathname + x.search; };
const render = () => {
const typed = $('viralUrl').value.trim();
const l = build(typed || vp.value);
$('viralLink').textContent = l || (typed ? 'That is not a page on instantadpay.com.' : '…');
const l = build(vp.value);
$('viralLink').textContent = l || '…';
const sh = $('viralShare'); sh.innerHTML = '';
if (!l) return;
const title = (!typed && vp.selectedOptions[0]) ? vp.selectedOptions[0].textContent.replace(/^Article: /, '') : 'InstantAdPay';
const title = vp.selectedOptions[0] ? vp.selectedOptions[0].textContent.replace(/^Article: /, '') : 'InstantAdPay';
[linkBtn('https://x.com/intent/tweet?url=' + enc(l) + '&text=' + enc(title), 'X'),
linkBtn('https://www.facebook.com/sharer/sharer.php?u=' + enc(l), 'Facebook'),
linkBtn('https://t.me/share/url?url=' + enc(l) + '&text=' + enc(title), 'Telegram'),
@@ -227,8 +219,7 @@ window.IAPPromo = (function () {
if (navigator.share) { const b = document.createElement('button'); b.className = 'btn small sec'; b.type = 'button'; b.textContent = 'Share'; b.onclick = async () => { try { await navigator.share({ title, url: l }); } catch (e) {} }; sh.appendChild(b); }
};
fetch('/api/pages').then(r => r.json()).then(r => { vp.innerHTML = (r.pages || []).map(pg => '<option value="' + esc(pg.path) + '">' + esc(pg.title) + '</option>').join(''); render(); }).catch(() => { vp.innerHTML = '<option value="/">Home page</option>'; render(); });
vp.onchange = () => { $('viralUrl').value = ''; render(); };
$('viralUrl').oninput = render;
vp.onchange = render;
$('viralCopy').onclick = async () => { const l = $('viralLink').textContent; if (!/^https:/.test(l)) return; try { await navigator.clipboard.writeText(l); status('Link copied.', 'ok'); } catch (e) { status('Copy failed.', 'bad'); } };
}
// objections