Files

152 lines
14 KiB
JavaScript

// 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 => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[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 = '<svg width="34" height="34" viewBox="0 0 34 34" aria-hidden="true"><circle cx="17" cy="8" r="5" fill="#C4371B"></circle><path d="M17 13 V20 M17 20 L8 29 M17 20 L26 29 M17 20 V30" stroke="#0B2730" stroke-width="2.4" fill="none" stroke-linecap="round"></path></svg>';
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'], ['/guides', 'Guides'], ['/my', 'My ad tree']];
h.innerHTML = '<a class="skip" href="#main">Skip to content</a><div class="wrap"><a class="brand" href="/" aria-label="ViralAdSource, front page">' + MARK + '<span class="wm">ViralAd<b>Source</b></span></a>'
+ '<nav class="links" aria-label="Main">' + links.map(l => '<a href="' + l[0] + '"' + (l[0] === active ? ' class="on" aria-current="page"' : '') + '>' + l[1] + '</a>').join('') + '</nav>'
+ '<div class="row"><a class="btn sm" id="navSign" href="/my">Sign in</a><a class="btn sm ink" href="/my#post">Post your ad free</a></div></div>';
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. 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('<span class="chip coral">Boosted</span>');
if (t.credit) tags.push('<span class="chip">Featured with credits</span>');
if (t.rank) tags.push('<span class="chip grey">#' + t.rank + '</span>');
return '<article class="ad' + (t.boosted ? ' boosted' : '') + (t.credit ? ' credit' : '') + (o.big ? ' big' : '') + '">'
+ '<div class="tag"><span>' + tags.join(' ') + '</span><span>' + n(t.reshares) + ' reshare' + (t.reshares === 1 ? '' : 's') + '</span></div>'
+ '<h3>' + esc(t.headline) + '</h3><p>' + esc(t.line1) + (t.line2 ? ' ' + esc(t.line2) : '') + '</p>'
+ '<div class="foot"><a class="visit" data-go="' + t.id + '" data-p="' + esc(o.place || 'card') + '"' + (o.share ? ' data-s="' + esc(o.share) + '"' : '') + ' target="_blank" rel="noopener sponsored" href="' + goHref(t.id, o.place, o.share) + '">Visit ' + esc(t.host) + '</a>'
+ '<span class="muted">' + esc(t.owner) + '</span></div>' + (o.extra || '') + '</article>';
}
// 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 = '<b>Part of the network</b> &middot; One account across the network: ' + list.map(s => s.id === 'viraladsource'
? '<span class="here" aria-current="page">' + esc(s.name) + '</span>' : '<a href="' + esc(s.go || s.url) + '" target="_blank" rel="noopener nofollow">' + esc(s.name) + '</a>').join(' &middot; '); };
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 = '<div class="wrap"><p><b>ViralAdSource</b>: every ad has a source. Ad credits buy advertising, not income. Nothing is promised.</p>'
+ '<p><a href="/">Front page</a> &middot; <a href="/#how">How it spreads</a> &middot; <a href="/rewards">Rewards</a> &middot; <a href="/my">My ad tree</a> &middot; <a href="/boost">Boost</a> &middot; <a href="/promote">Promote</a> &middot; <a href="/guides">Guides</a> &middot; <a href="/guides/faq">FAQ</a></p>'
+ '<p><a href="/terms">Terms</a> &middot; <a href="/disclaimer">Earnings Disclaimer</a> &middot; <a href="/privacy">Privacy</a> &middot; <a href="/contract">Contract</a> &middot; <a href="/ledger">Ledger</a> &middot; <a href="https://instantadpay.com/support?from=viraladsource" target="_blank" rel="noopener">Support</a></p>'
+ '<p>&copy; 2026 TrustClickz</p><p class="netline"></p></div>';
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 = '<b>' + who(c) + ' boosted an ad</b><br><span>' + (c.resharer ? 'through @' + esc(c.resharer) + '\'s branch, paid in the same transaction' : 'split on chain by the contract') + '</span>'; }
else if (c.kind === 'reshare') { el.href = '/#board'; el.innerHTML = '<b>' + who(c) + ' reshared an ad</b><br><span>a new branch, step ' + esc(c.step) + ' from the source</span>'; }
else { el.href = '/#board'; el.innerHTML = '<b>' + who(c) + ' posted a new ad</b><br><span>' + esc(c.headline) + '</span>'; }
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
(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 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: '', proposalNote: '', tiersNote: tier.every ? 'Bigger tiers are credited at once and withdrawable after ' + (tier.lockDays || 14) + ' days.' : '',
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();
})();
// Network Weekend ribbon (Marty 2026-11-17): netweekend.js paints it only while a network event is live (dates from the hub through
// /api/network-deals). Not on the admin page, never inside a frame.
(function () {
if (/^\/admin/.test(location.pathname)) return;
try { if (window.top !== window) return; } catch (e) { return; }
var s = document.createElement('script'); s.src = '/assets/netweekend.js?v=20261117'; s.defer = true; s.setAttribute('data-site', 'viraladsource'); document.head.appendChild(s);
})();
// network ad zones (2026-11-17, the ViralAdBlitz pattern): LinkSpin zones on Marty's LinkSpin account for viraladsource.com, made through
// LinkSpin's named admin zone route: footer wide 728x90 (ls-2b9438), footer phone 320x50 (ls-df436d), ledger 468x60
// (ls-c469a6); the not-found page carries ls-4108d7. Admin pages get none.
(function () {
const ZONES = { footWide: 'ls-2b9438', footPhone: 'ls-df436d', ledger: 'ls-c469a6' };
function zone(el, id) {
if (!el || el.dataset.zoned) return; el.dataset.zoned = '1'; el.className = 'net-zone'; el.style.cssText = 'margin:18px auto;text-align:center;max-width:100%';
const lab = document.createElement('div'); lab.textContent = 'Network'; lab.style.cssText = 'font-size:11px;letter-spacing:1px;opacity:.7;margin-bottom:4px';
const s = document.createElement('script'); s.async = true; s.src = 'https://linkspin.app/z.js'; s.setAttribute('data-zone', id);
el.appendChild(lab); el.appendChild(s);
}
function run() {
const p = location.pathname.replace(/\/$/, '') || '/';
if (p === '/admin' || document.body.dataset.noZones) return;
if (p === '/ledger') { const t = document.getElementById('rows'); const sec = t && t.closest('section'); if (sec && sec.parentNode) { const d = document.createElement('div'); sec.parentNode.insertBefore(d, sec.nextSibling); zone(d, ZONES.ledger); } }
const za = document.createElement('div'); document.body.appendChild(za); zone(za, window.innerWidth >= 760 ? ZONES.footWide : ZONES.footPhone);
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', run); else run();
})();