// An ad through a reshare link (/s/): the ad, whose branch it came through, "Reshare this ad" (the member's own unique link, // under this one) and "Join free" for people new to the network. The visit counts as a verified view for that branch once seen. (async function () { const $ = VAS.$, esc = VAS.esc; const code = (location.pathname.match(/^\/s\/([a-z0-9]{8})/) || [])[1]; const d = await VAS.wire('share', code).catch(() => ({})); if (!d.ad) { $('adBox').innerHTML = '

' + esc(d.error || 'That ad is not running right now.') + ' See the board

'; $('reshareBox').hidden = true; return; } const sh = d.share || {}; document.title = d.ad.headline + ' | ViralAdSource'; $('chain').textContent = sh.step > 0 ? 'Reshared by @' + (sh.resharer || 'a member') + ' ยท step ' + sh.step + ' from the source' + (sh.owner ? ' (@' + sh.owner + ')' : '') : 'At the source' + (sh.owner ? ': @' + sh.owner + '\'s ad' : ''); $('adBox').innerHTML = VAS.adCard(d.ad, { big: true, place: 'share', share: sh.code }); VAS.featured($('featured'), d); const out = (url, note) => { $('reshareOut').innerHTML = '
' + esc(url) + '
' + (note ? '

' + esc(note) + '

' : ''); $('cp').onclick = () => VAS.copy(url, $('cp')); }; if (d.mine) out(d.mine.url, d.mine.own ? 'This is your own ad: this is its source link.' : 'Your reshare link for this ad.'); $('reshareBtn').onclick = async () => { const me = await VAS.getJSON('/api/me'); if (!me.signedIn) { location.href = '/my?back=' + encodeURIComponent(location.pathname); return; } const r = await VAS.post('/api/my/reshare', { adId: d.ad.id, from: sh.code }); if (r.error) return VAS.status(r.error, 'err'); out(r.url, r.own ? 'This is your own ad: share its source link.' : r.created ? 'Your new branch: step ' + r.step + ' from the source. Share this link anywhere.' : 'You already reshared this ad. Here is your link again.'); VAS.status(''); }; })();