// Shared page helpers (VAB namespace, modelled on VBB / Downline Banners common.js): nav, the amber ticker, verified visits, // ad cards, footer (legal, company line, the network line from the hub), network ad zones and toasts of real events. window.VAB = (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'); function status(msg, cls) { const el = $('status'); if (!el) return; el.hidden = !msg; el.className = 'note ' + (cls || ''); el.textContent = msg || ''; } 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 || {}) }); function renderNav(active) { const nav = document.createElement('nav'); nav.className = 'top'; const links = [['/#board', 'Top ads'], ['/my', 'My page'], ['/boost', 'Boost'], ['/ledger', 'Ledger'], ['/contract', 'Contract'], ['/promote', 'Promote']]; nav.innerHTML = '
ViralAdBlitzLIVE' + 'Post my free text ad
'; document.body.prepend(nav); const tk = document.createElement('div'); tk.className = 'ticker'; tk.id = 'ticker'; tk.setAttribute('aria-label', 'Live ticker of the newest text ads'); tk.innerHTML = 'Loading the wire...'; nav.after(tk); if (framed) document.querySelectorAll('a[href="/my"]').forEach(a => { a.target = '_blank'; a.rel = 'noopener'; }); } // a link through the click relay: placement + the visitor's verified token once their visit has verified const goHref = (id, p) => '/go/' + id + '?p=' + encodeURIComponent(p || 'site') + (vt ? '&v=' + vt : ''); function decorate() { document.querySelectorAll('a[data-go]').forEach(a => { a.href = goHref(a.dataset.go, a.dataset.p); }); } function renderTicker(items) { const el = $('ticker'); if (!el) return; if (!items || !items.length) { el.innerHTML = 'The wire is quiet. Post the first text ad.'; return; } const one = items.map(t => '' + (t.boosted ? '★ BOOSTED: ' : '▲ ') + esc(t.headline) + ' · ' + esc(t.owner) + '').join(''); const reps = Math.max(1, Math.ceil(8 / items.length)); el.innerHTML = '
' + one.repeat(reps) + one.repeat(reps) + '
'; } // a newsprint card for a text ad (front board, member page Boosted places) function paper(t, tag, place) { return '
' + (t.boosted ? '★ BOOSTED' + (tag ? ' · ' : '') : '') + esc(tag || '') + '' + '

' + esc(t.headline) + '

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

' + 'Visit ' + esc(t.host) + ' · ' + esc(t.owner) + '
'; } // the page's data and its verified visit: the ads come with a ticket; after visitSeconds of the page being visible the // visit is sent once, and from then on clicks carry the verified token async function wire(page, u) { const src = document.referrer || ''; const d = await getJSON('/api/wire?page=' + encodeURIComponent(page) + (u ? '&u=' + encodeURIComponent(u) : '') + (src ? '&src=' + encodeURIComponent(src) : '')); renderTicker(d.ticker || []); if (d.ticket) { const need = (d.seconds || 6) * 1000; let seen = 0, last = Date.now(), sent = false; const step = 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('vab:verified', { detail: r })); } }; const iv = setInterval(step, 500); document.addEventListener('visibilitychange', () => { last = Date.now(); }); } return d; } // network ad zones (LinkSpin zones on Marty's account for viraladblitz.com, the VBB pattern). EMPTY until the zones are created // on LinkSpin: footer wide 728x90, footer phone 320x50, ledger 468x60, Boost page 300x250, My page 468x60; 404 in server.js. const ZONES = { footWide: '', footPhone: '', ledger: '', boost: '', my: '' }; function zone(el, key) { if (!el || el.dataset.zoned || !ZONES[key]) return; el.dataset.zoned = '1'; el.classList.add('net-zone'); const lab = document.createElement('div'); lab.className = 'net-zone-label'; lab.textContent = 'Network'; const s = document.createElement('script'); s.async = true; s.src = 'https://linkspin.app/z.js'; s.setAttribute('data-zone', ZONES[key]); el.appendChild(lab); el.appendChild(s); } function pageZones() { const p = location.pathname.replace(/\/$/, '') || '/'; if (p === '/admin') return; const after = (el, key) => { if (!el || !el.parentNode) return; const d = document.createElement('div'); el.parentNode.insertBefore(d, el.nextSibling); zone(d, key); }; if (p === '/ledger') after($('rows') && $('rows').closest('section'), 'ledger'); if (p === '/boost') after(document.querySelector('main section'), 'boost'); if (p === '/my') after($('dash'), 'my'); const za = document.createElement('div'); za.className = 'wrap'; document.body.appendChild(za); zone(za, window.innerWidth >= 760 ? 'footWide' : 'footPhone'); } 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'], ['stackpol', 'Stack POL', 'https://stackpol.com'], ['earnerscorner', 'Earners Corner', 'https://earnerscorner.com']].map(a => ({ id: a[0], name: a[1], url: a[2] })); 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 === 'viraladblitz' || /viraladblitz\.com/.test(s.url)) ? '' + esc(s.name) + '' : '' + esc(s.name) + '').join(' · '); }; paint(NET); fetch('/api/network-sites').then(r => r.json()).then(l => { if (Array.isArray(l) && l.length) paint(l.some(s => s.id === 'viraladblitz') ? l : l.concat([NET[4]])); }).catch(() => {}); } function renderFooter() { pageZones(); const f = document.createElement('footer'); f.className = 'foot'; f.innerHTML = '

ViralAdBlitz, the network\'s text ad wire

' + '

A Boost buys advertising, not income. Nothing is promised.

' + '

Front page · My page · Boost · Promote

' + '' + '

TrustClickz · 615 Green Valley Drive, Moody, AL 35004

'; document.body.appendChild(f); netLine(f.querySelector('.netline')); toasts(); } // live toasts: real new ads and Boosts only, bottom-left, one at a time, never older than 30 minutes 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 show = c => { const el = document.createElement('a'); el.className = 'toast'; if (c.kind === 'boost') { el.href = '/ledger'; el.innerHTML = '' + (c.name ? '@' + esc(c.name) : 'A member') + ' just boosted an ad
' + (c.levels ? (c.levels === 1 ? '1 sponsor' : c.levels + ' sponsors') + ' paid in the same transaction' : 'paid on-chain, split by the contract') + ''; } else { el.href = '/'; el.innerHTML = '' + (c.name ? '@' + esc(c.name) : 'A member') + ' posted a new text 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' : ''; return { $, esc, getConfig, short, framed, status, getJSON, post, n, renderNav, renderFooter, renderTicker, paper, wire, decorate, goHref, polOf, when }; })();