// My page: sign in (network or wallet), post or edit the one free text ad, the member's page link, their line, Boost delivery, // and what the contract has paid them. (async function () { VAB.renderNav('/my'); VAB.renderFooter(); VAB.wire('other').catch(() => {}); const $ = VAB.$, esc = VAB.esc; const c = await VAB.getConfig().catch(() => ({})); const me = await VAB.getJSON('/api/me'); if (!me.signedIn) { // signed in on InstantAdPay already? one quick hop there and back signs you in here too try { const ss = await VAB.getJSON('/api/sso/status'); if (ss && ss.check) { location.replace('/sso/start?mode=check&via=iap&to=' + encodeURIComponent('/my')); return; } } catch (e) {} $('signin').hidden = false; if (!c.sso) { $('viaIap').hidden = true; $('viaLs').hidden = true; } if (c.joinUrl) $('joinLink').href = c.joinUrl; $('viaWallet').onclick = async () => { try { VAB.status('Check your wallet for the sign-in message.'); await VABWallet.signIn(); location.reload(); } catch (e) { VAB.status(String(e && e.message || e).slice(0, 300), 'err'); } }; return; } $('signout').onclick = async () => { await VAB.post('/api/auth/logout'); location.reload(); }; const counter = (inp, out, max) => { const f = () => { out.textContent = inp.value.length + ' / ' + max; }; inp.addEventListener('input', f); f(); }; const copyText = (t, b) => { try { navigator.clipboard.writeText(t); b.textContent = 'Copied'; setTimeout(() => { b.textContent = 'Copy my link'; }, 1400); } catch (e) {} }; async function load() { const d = await VAB.getJSON('/api/my'); if (d.error) { VAB.status(d.error, 'err'); return; } $('dash').hidden = false; const a = d.ad; const lim = c.ad || { headline: 60, line: 90 }; $('stats').innerHTML = '
Share it anywhere. It shows your ad and the five people above you, and everyone who joins through it shows your ad on their page.
' : 'Your page address uses your network username. Sign in through InstantAdPay or LinkSpin once and it is set.
'; if ($('copyPage')) $('copyPage').onclick = () => copyText(d.page, $('copyPage')); if (!d.netVerified) { $('adNote').innerHTML = 'Text ads are free for network members. This wallet is not in the network yet: join InstantAdPay free, link this wallet there, then sign in here through InstantAdPay.'; $('adForm').hidden = true; } else { $('adForm').hidden = false; if (a) { $('adHead').textContent = 'Your text ad' + (a.status !== 'live' ? ' (' + a.status + ')' : ''); $('fHead').value = a.headline; $('fL1').value = a.line1; $('fL2').value = a.line2 || ''; $('fLink').value = a.link; $('adSave').textContent = 'Save changes'; } counter($('fHead'), $('cHead'), lim.headline); counter($('fL1'), $('cL1'), lim.line); counter($('fL2'), $('cL2'), lim.line); } $('line').innerHTML = (d.line || []).length ? 'The people above you in the network, nearest first. Your page shows the first five who have an ad here.
' + d.line.map(x => '' + (d.lineOk === false ? 'The network line could not be read just now. Try again in a minute.' : 'No sponsor line is known for you in the network yet.') + '
'; $('boosts').innerHTML = (d.boosts || []).length ? d.boosts.map(b => 'No Boosts yet. A Boost is $' + (c.boost ? c.boost.usd : 5) + ' once and buys ' + VAB.n(c.boost ? c.boost.views : 500) + ' guaranteed network views for your ad.
'; const ex = c.explorer || 'https://polygonscan.com'; $('earned').innerHTML = (d.earned && d.earned.items.length) ? d.earned.items.map(x => 'Nothing yet. The contract pays a level share in the same transaction when someone in your team buys a Boost, if you have bought one yourself. Advertising, not income. Nothing is promised.
'; } $('adForm').addEventListener('submit', async e => { e.preventDefault(); $('adSave').disabled = true; VAB.status('Checking your link...'); const r = await VAB.post('/api/my/ad', { headline: $('fHead').value, line1: $('fL1').value, line2: $('fL2').value, link: $('fLink').value }); $('adSave').disabled = false; if (r.error) return VAB.status(r.error, 'err'); VAB.status(r.created ? 'Posted. Your ad is live on your page and on your team\'s pages.' : 'Saved. Your ad shows the new text everywhere.', 'ok'); load(); }); await load(); })();