// Shared page helpers (VAS namespace, the network common.js pattern): header, footer (legal, company line, the network line from the // hub), verified visits, ad cards, toasts of real events, small formatters. The watershed look lives in vas.css. window.VAS = (function () { let cfgP = null, vt = null; const $ = id => document.getElementById(id); const esc = s => String(s == null ? '' : s).replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); const getConfig = () => cfgP || (cfgP = fetch('/api/config').then(r => r.json())); const short = a => a ? a.slice(0, 6) + '...' + a.slice(-4) : ''; const framed = (() => { try { return window.top !== window.self; } catch (e) { return true; } })(); const n = x => Number(x || 0).toLocaleString('en-US'); const pct = bps => (Number(bps || 0) / 100).toFixed(Number(bps) % 100 ? 1 : 0) + '%'; const usd = c => '$' + (Number(c || 0) / 100).toFixed(2); function status(msg, cls, id) { const el = $(id || 'status'); if (!el) return; el.hidden = !msg; el.className = 'note ' + (cls || ''); el.textContent = msg || ''; if (msg) el.scrollIntoView({ block: 'nearest', behavior: 'smooth' }); } async function getJSON(url, opts) { const r = await fetch(url, opts); let j = {}; try { j = await r.json(); } catch (e) {} if (!r.ok && !j.error) j.error = 'Request failed (' + r.status + ')'; j._status = r.status; return j; } const post = (url, body) => getJSON(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) }); const MARK = ''; function renderNav(active) { const h = document.createElement('header'); h.className = 'top'; const links = [['/#how', 'How it spreads'], ['/#board', 'Reshare board'], ['/rewards', 'Rewards'], ['/boost', 'Boost'], ['/ledger', 'Ledger'], ['/my', 'My ad tree']]; h.innerHTML = '
' + MARK + 'ViralAdSource' + '' + '
Sign inPost your ad free
'; document.body.prepend(h); getConfig().then(c => { if (c.staging) { const b = document.createElement('div'); b.className = 'stage-bar'; b.textContent = 'Staging copy for testing. Numbers marked as proposals are not final. No real payouts happen here.'; h.after(b); } }).catch(() => {}); getJSON('/api/me').then(m => { if (m.signedIn) { const a = $('navSign'); if (a) { a.textContent = m.username ? '@' + m.username : short(m.address); } } }).catch(() => {}); if (framed) document.querySelectorAll('a[href^="/my"]').forEach(a => { a.target = '_blank'; a.rel = 'noopener'; }); } // a link through the click relay: share + placement + the visitor's verified token once their visit has verified const goHref = (id, p, s) => '/go/' + id + '?p=' + encodeURIComponent(p || 'site') + (s ? '&s=' + s : '') + (vt ? '&v=' + vt : ''); function decorate() { document.querySelectorAll('a[data-go]').forEach(a => { a.href = goHref(a.dataset.go, a.dataset.p, a.dataset.s); }); } // an ad card. o = { place, share, big, extra (html) } function adCard(t, o) { o = o || {}; const tags = []; if (t.boosted) tags.push('Boosted'); if (t.credit) tags.push('Featured with credits'); if (t.rank) tags.push('#' + t.rank + ''); return '
' + '
' + tags.join(' ') + '' + n(t.reshares) + ' reshare' + (t.reshares === 1 ? '' : 's') + '
' + '

' + esc(t.headline) + '

' + esc(t.line1) + (t.line2 ? ' ' + esc(t.line2) : '') + '

' + '
Visit ' + esc(t.host) + '' + '' + esc(t.owner) + '
' + (o.extra || '') + '
'; } // the page's data and its verified visit: ads come with a ticket; after visitSeconds of the page being visible the visit is sent once async function wire(page, s) { const src = document.referrer || ''; let hunt = /[?&#]ph=/.test(location.search + location.hash); try { hunt = hunt || !!sessionStorage.getItem('ph.token'); } catch (e) {} const d = await getJSON('/api/wire?page=' + encodeURIComponent(page) + (s ? '&s=' + encodeURIComponent(s) : '') + (src ? '&src=' + encodeURIComponent(src) : '') + (hunt ? '&hunt=1' : '')); if (d.ticket) { const need = (d.seconds || 6) * 1000; let seen = 0, last = Date.now(), sent = false; const iv = setInterval(async () => { const now = Date.now(); if (document.visibilityState === 'visible') seen += now - last; last = now; if (!sent && seen >= need) { sent = true; clearInterval(iv); const r = await post('/api/visit/seen', { ticket: d.ticket, visibleMs: seen }).catch(() => ({})); if (r.vt) { vt = r.vt; decorate(); } document.dispatchEvent(new CustomEvent('vas:verified', { detail: r })); } }, 500); document.addEventListener('visibilitychange', () => { last = Date.now(); }); } return d; } function featured(el, d) { if (!el) return; const f = d.featured || []; el.hidden = !f.length; if (f.length) el.querySelector('.ads').innerHTML = f.map(t => adCard(t, { place: 'credit' })).join(''); } const NET = [['iap', 'InstantAdPay', 'https://instantadpay.com'], ['linkspin', 'LinkSpin', 'https://linkspin.app'], ['dlb', 'Downline Banners', 'https://downlinebanners.com'], ['vbb', 'Viral Banner Blitz', 'https://viralbannerblitz.com'], ['viraladblitz', 'ViralAdBlitz', 'https://viraladblitz.com'], ['downlinehydra', 'DownlineHydra', 'https://downlinehydra.com'], ['fivex', '5xYourTeam', 'https://5xyourteam.com'], ['stackpol', 'Stack POL', 'https://stackpol.com'], ['earnerscorner', 'Earners Corner', 'https://earnerscorner.com']].map(a => ({ id: a[0], name: a[1], url: a[2] })); const HERE = { id: 'viraladsource', name: 'ViralAdSource', url: 'https://viraladsource.com' }; function netLine(el) { if (!el) return; const paint = list => { el.innerHTML = 'Part of the network · One account across the network: ' + list.map(s => s.id === 'viraladsource' ? '' + esc(s.name) + '' : '' + esc(s.name) + '').join(' · '); }; paint(NET.concat([HERE])); fetch('/api/network-sites').then(r => r.json()).then(l => { if (Array.isArray(l) && l.length) paint(l.some(s => s.id === 'viraladsource') ? l : l.concat([HERE])); }).catch(() => {}); } function renderFooter() { const f = document.createElement('footer'); f.className = 'foot'; f.innerHTML = '

ViralAdSource: every ad has a source. Ad credits buy advertising, not income. Nothing is promised.

' + '

Front page · How it spreads · Rewards · My ad tree · Boost · Promote

' + '

Terms · Earnings Disclaimer · Privacy · Contract · Ledger · Support

' + '

TrustClickz · 615 Green Valley Drive, Moody, AL 35004

'; document.body.appendChild(f); netLine(f.querySelector('.netline')); toasts(); } let toastsOn = false; function toasts() { if (toastsOn) return; toastsOn = true; const seen = new Set(); let first = true; const box = document.createElement('div'); box.className = 'toasts'; box.setAttribute('aria-live', 'polite'); document.body.appendChild(box); const who = c => c.name ? '@' + esc(c.name) : 'A member'; const show = c => { const el = document.createElement('a'); el.className = 'toast'; if (c.kind === 'boost') { el.href = '/ledger'; el.innerHTML = '' + who(c) + ' boosted an ad
' + (c.resharer ? 'through @' + esc(c.resharer) + '\'s branch, paid in the same transaction' : 'split on chain by the contract') + ''; } else if (c.kind === 'reshare') { el.href = '/#board'; el.innerHTML = '' + who(c) + ' reshared an ad
a new branch, step ' + esc(c.step) + ' from the source'; } else { el.href = '/#board'; el.innerHTML = '' + who(c) + ' posted a new ad
' + esc(c.headline) + ''; } box.appendChild(el); requestAnimationFrame(() => el.classList.add('in')); setTimeout(() => { el.classList.remove('in'); setTimeout(() => el.remove(), 400); }, 7000); }; const tick = async () => { const d = await getJSON('/api/recent').catch(() => null); const all = (d && d.items) || []; const fresh = all.filter(c => !seen.has(c.key)); all.forEach(c => seen.add(c.key)); const list = first ? fresh.slice(0, 1) : fresh.reverse(); first = false; list.slice(0, 3).forEach((c, i) => setTimeout(() => show(c), 1500 + i * 8000)); }; tick(); setInterval(tick, 25000); } const polOf = (w, d) => { try { const k = BigInt(w || 0); const v = Number(k / 10n ** 12n) / 1e6; return v.toFixed(d != null ? d : (v >= 100 ? 2 : 4)); } catch (e) { return '0'; } }; const when = t => t ? new Date(t).toLocaleString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }) + ' CT' : ''; async function copy(text, btn) { try { await navigator.clipboard.writeText(text); if (btn) { const o = btn.textContent; btn.textContent = 'Copied'; setTimeout(() => { btn.textContent = o; }, 1600); } } catch (e) { if (btn) { btn.textContent = 'Select the link above to copy it'; } } } return { MARK, $, esc, getConfig, short, framed, status, getJSON, post, n, pct, usd, renderNav, renderFooter, adCard, wire, featured, decorate, goHref, polOf, when, copy }; })(); // every page: header, footer and the numbers from /api/config (proposals are labelled as proposals) (function () { const boot = () => { VAS.renderNav(document.body.dataset.nav || ''); VAS.renderFooter(); VAS.getConfig().then(c => { const sp = c.split || {}, rw = c.reward || {}, cr = c.credits || {}, b = c.boost || {}; const prop = sp.live ? '' : '(proposal)'; const lv = sp.levelBps || []; const lvTxt = lv.length ? (lv.every(x => x === lv[0]) ? lv.length + ' x ' + VAS.pct(lv[0]) : lv.map(VAS.pct).join(' / ')) : 'none'; const tier = (rw.tiers || [])[0] || {}; const V = { cut: VAS.pct(sp.resharerBps), pot: VAS.pct(sp.potBps), levels: lvTxt, signup: VAS.usd(rw.cents), cap: String(rw.dailyCap), lockDays: String(tier.lockDays || 14), creditsPer: String(cr.per), creditsViews: String(cr.views), boostDays: String(b.days), boostUsd: '$' + b.usd, headline: String((c.ad || {}).headline || 60), proposalTag: prop, proposalNote: sp.live ? '' : 'The percentages and amounts shown are proposals and are not final yet.', payoutsNote: rw.payouts ? '' : 'Sign-up reward payouts are switched off for now: verified rewards wait in the pending ledger.' }; document.querySelectorAll('[data-cfg]').forEach(el => { const k = el.dataset.cfg; if (V[k] != null) el.textContent = V[k]; }); }).catch(() => {}); }; if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot); else boot(); })();