// My ad tree (the member dashboard): sign in (network account through the hub, or wallet), the free ad with the spin-link picker, // the ad's family tree (branch, step, reshares under it, views, clicks, sign-ups, Boosts), the ads I reshared, credits and rewards. (async function () { const $ = VAS.$, esc = VAS.esc; VAS.wire('other').catch(() => {}); const c = await VAS.getConfig().catch(() => ({})); const me = await VAS.getJSON('/api/me'); const back = new URLSearchParams(location.search).get('back'); if (!me.signedIn) { try { const ss = await VAS.getJSON('/api/sso/status'); if (ss && ss.check) { location.replace('/sso/start?mode=check&to=' + encodeURIComponent(location.pathname + location.search)); return; } } catch (e) {} $('signin').hidden = false; if (c.joinUrl) $('joinLink').href = c.joinUrl; $('walletBtn').onclick = async () => { try { VAS.status('Check your wallet for the sign-in message.', '', 'status'); await VASWallet.signIn(); location.href = back && /^\/s\/[a-z0-9]{8}$/.test(back) ? back : '/my'; } catch (e) { VAS.status(String(e && e.message || e).slice(0, 300), 'err'); } }; return; } if (back && /^\/s\/[a-z0-9]{8}$/.test(back)) { location.replace(back); return; } $('dash').hidden = false; $('logout').onclick = async () => { await VAS.post('/api/auth/logout'); location.reload(); }; $('logoutAll').onclick = async () => { $('logoutAll').disabled = true; await VAS.post('/api/auth/logout-everywhere'); location.reload(); }; // spin-link picker: only the member's own LinkSpin spin links (LinkSpin confirms again on every save) let spins = null; $('loadSpins').onclick = async () => { const box = $('spinList'); box.innerHTML = '
Asking LinkSpin for your spin links...
'; const r = await VAS.getJSON('/api/my/spins').catch(() => ({ error: 'LinkSpin did not answer. Try again in a minute.' })); if (r.error) { box.innerHTML = '' + esc(r.error) + '
'; return; } spins = r.spins || []; if (!r.account) { box.innerHTML = 'No LinkSpin account was found for your network username yet. Open LinkSpin
'; return; } if (!spins.length) { box.innerHTML = 'You have no spin links yet. Make one on LinkSpin, then pick it here.
'; return; } box.innerHTML = spins.map((x, i) => '').join(''); box.querySelectorAll('button[data-i]').forEach(b => { b.onclick = () => { const x = spins[Number(b.dataset.i)]; $('link').value = x.url; box.querySelectorAll('button').forEach(y => y.classList.remove('on')); b.classList.add('on'); $('track').checked = false; VAS.status('Spin link picked. Save your ad to use it.', 'ok'); }; }); }; // the AI ad writer (2026-11-17): 3 suggestions written only from the member's own page; picking one fills the form, nothing is posted if (c.aiWriter) { $('aiBox').hidden = false; let opts = []; $('aiWrite').onclick = async () => { const box = $('aiList'), url = $('link').value.trim(); if (!/^https?:\/\/\S+\.\S+/i.test(url)) { box.innerHTML = 'Put your link in the Your link box first (starting with https://), then tap the button again.
'; $('link').focus(); return; } $('aiWrite').disabled = true; box.innerHTML = 'Reading your page and writing 3 ads. This takes a few seconds...
'; const r = await VAS.post('/api/my/adwriter', { url }).catch(() => ({ error: 'The ad writer did not answer. Try again in a minute.' })); $('aiWrite').disabled = false; if (r.error) { box.innerHTML = '' + esc(r.error) + '
'; return; } opts = r.options || []; box.innerHTML = opts.map((o, i) => '').join('') + 'Tap one to use it. Check every word is true for your offer before you post.' + (typeof r.left === 'number' ? ' Ad writes left today: ' + r.left + '.' : '') + '
'; box.querySelectorAll('button[data-ai]').forEach(b => { b.onclick = () => { const o = opts[Number(b.dataset.ai)]; $('headline').value = o.headline; $('line1').value = o.line; box.querySelectorAll('button[data-ai]').forEach(y => y.classList.remove('on')); b.classList.add('on'); VAS.status('Filled in. Edit it as you like, then tap the button below to save.', 'ok'); }; }); }; } $('adForm').addEventListener('submit', async e => { e.preventDefault(); $('saveAd').disabled = true; const r = await VAS.post('/api/my/ad', { headline: $('headline').value, line1: $('line1').value, line2: $('line2').value, link: $('link').value.trim(), track: $('track').checked }); $('saveAd').disabled = false; if (r.error) return VAS.status(r.error, 'err'); VAS.status(r.created ? 'Your ad is live. Share your source link below: every reshare grows a branch.' : 'Saved.', 'ok'); load(); }); $('copySource').onclick = () => VAS.copy($('sourceUrl').textContent, $('copySource')); async function load() { const d = await VAS.getJSON('/api/my'); if (d.error) return VAS.status(d.error, 'err'); $('who').innerHTML = 'Signed in as ' + (d.username ? '@' + esc(d.username) : '' + esc(VAS.short(d.address)) + '') + (d.netVerified ? ' · network member' : ' · not found in the network yet: sign in with your network account to post and reshare') + (d.test ? ' · staging test member' : ''); const a = d.ad, t = d.tree; if (a) { $('adTitle').textContent = 'My ad'; $('headline').value = a.headline; $('line1').value = a.line1; $('line2').value = a.line2 || ''; $('link').value = a.link; $('track').checked = a.track !== false; $('saveAd').textContent = 'Save changes'; $('treeChip').textContent = a.status + (a.boostedUntil && a.boostedUntil > Date.now() ? ' · boosted until ' + VAS.when(a.boostedUntil) : ''); } if (d.source) { $('sourceBox').hidden = false; $('sourceUrl').textContent = d.source.url; } const cr = d.credits || {}, rw = d.rewards || {}; $('myStats').innerHTML = [[t ? t.totals.shares : 0, 'reshares of my ad'], [t ? t.totals.reach : 0, 'furthest step'], [a ? a.views : 0, 'verified views'], [a ? a.vclicks : 0, 'verified clicks'], [cr.balance, 'ad credits']].map(x => '