a6c72a4a40
Pages, footers and the site assistant now name only TrustClickz; the footer reads "(c) 2026 TrustClickz". Contact stays the network support link. QA checks updated to assert no street address is shown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
12 KiB
JavaScript
126 lines
12 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 => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[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'], ['/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. 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('<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> · 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(' · '); };
|
|
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> · <a href="/#how">How it spreads</a> · <a href="/rewards">Rewards</a> · <a href="/my">My ad tree</a> · <a href="/boost">Boost</a> · <a href="/promote">Promote</a></p>'
|
|
+ '<p><a href="/terms">Terms</a> · <a href="/disclaimer">Earnings Disclaimer</a> · <a href="/privacy">Privacy</a> · <a href="/contract">Contract</a> · <a href="/ledger">Ledger</a> · <a href="https://instantadpay.com/support?from=viraladsource" target="_blank" rel="noopener">Support</a></p>'
|
|
+ '<p>© 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 (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();
|
|
})();
|