e00b7b2f59
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
10 KiB
JavaScript
124 lines
10 KiB
JavaScript
// Shared page helpers (BL namespace, modelled on InstantAdPay common.js).
|
|
window.BL = (function () {
|
|
let cfgP = 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()));
|
|
function fmtPol(wei, dp) {
|
|
try { const w = BigInt(wei || 0); const whole = w / 10n ** 18n; const frac = (w % 10n ** 18n).toString().padStart(18, '0').slice(0, dp || 4).replace(/0+$/, '');
|
|
return whole.toString() + (frac ? '.' + frac : ''); } catch (e) { return '0'; }
|
|
}
|
|
const short = a => a ? a.slice(0, 6) + '...' + a.slice(-4) : '';
|
|
const framed = (() => { try { return window.top !== window.self; } catch (e) { return true; } })();
|
|
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 + ')'; return j; }
|
|
const post = (url, body) => getJSON(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body || {}) });
|
|
|
|
async function renderNav(active) {
|
|
const c = await getConfig().catch(() => ({}));
|
|
const n = document.createElement('nav');
|
|
const links = [['/', 'Home'], ['/board', 'Board'], ['/how', 'How it works'], ['/ledger', 'Ledger'], ['/join', 'Get a spot'], ['/promote', 'Promote'], ['/my', 'My Spots']];
|
|
n.innerHTML = '<div class="wrap"><a class="brand" href="/"><img src="/art/mark.svg" alt="" width="38" height="38"><span class="logo-wrap"><span class="logo">Downline <b>Banners</b></span>'
|
|
+ '<span class="byline">Part of the <b>Crypto Team Build</b> Network</span></span></a><div class="links">'
|
|
+ links.map(l => '<a href="' + l[0] + '"' + (l[0] === active ? ' class="active"' : '') + '>' + l[1] + '</a>').join('') + '</div></div>';
|
|
document.body.prepend(n);
|
|
if (c && c.chainId && c.chainId !== 137) {
|
|
const r = document.createElement('div'); r.className = 'rehearsal';
|
|
r.innerHTML = '<b>Rehearsal:</b> this runs on ' + esc(c.chainName) + '. Test POL only, no real money.';
|
|
n.after(r);
|
|
}
|
|
// inside a traffic-exchange frame, member and buy pages open in a new tab with the sponsor carried along
|
|
if (framed) document.querySelectorAll('nav a[href="/join"], nav a[href="/my"]').forEach(a => { a.target = '_blank'; a.rel = 'noopener'; });
|
|
}
|
|
function renderFooter() {
|
|
const za = document.createElement('div'); za.className = 'wrap bl-zone-foot'; document.body.appendChild(za);
|
|
zone(za, window.innerWidth >= 760 ? 'footWide' : 'footPhone');
|
|
const f = document.createElement('footer');
|
|
f.className = 'bl-foot';
|
|
f.innerHTML = '<div class="wrap"><p>Part of the Crypto Team Build Network</p>'
|
|
+ '<p class="muted small">A spot buys 300 guaranteed views on the board and a place in the line. Nothing is promised: you are paid only when spots sell after yours, and a spot can earn back less than it cost.</p>'
|
|
+ '<p class="small"><a href="/how">How it works</a> · <a href="/guides">Guides</a> · <a href="/board">Board</a> · <a href="/ledger">Live ledger</a> · <a href="/contract">Contract proof</a> · <a href="/promote">Promote</a> · <a href="/my">My Spots</a></p>'
|
|
// trust pack (Marty 2026-11-14): legal + proof links, company line, and the network line served by the hub
|
|
+ '<p class="small legal-links"><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" target="_blank" rel="noopener">Support</a></p>'
|
|
+ '<p class="muted small">© 2026 TrustClickz</p><p class="small netline"></p></div>';
|
|
document.body.appendChild(f);
|
|
netLine(f.querySelector('.netline'));
|
|
toasts();
|
|
}
|
|
// "Part of the network": the list comes from the hub through /api/network-sites, the built-in copy if it does not answer
|
|
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'], ['stackpol', 'Stack POL', 'https://stackpol.com'], ['earnerscorner', 'Earners Corner', 'https://earnerscorner.com']].map(a => ({ id: a[0], name: a[1], url: a[2] }));
|
|
// the footer links carry a referral username (Marty 2026-11-15): the signed-in member's own network username, else the sponsor this
|
|
// visitor came in on (/api/me names both; the bl.ref cookie holds a wallet, so it is never used here). Tracked links get it as s1
|
|
// (LinkSpin sends it on as ?ref=), plain links as ?ref=. Earners Corner takes none.
|
|
const REF_RE = /^[A-Za-z0-9_.-]{1,40}$/;
|
|
const okRef = v => !!v && REF_RE.test(v) && !/^0x[0-9a-f]{40}$/i.test(v);
|
|
function netRef(href, s, ref) {
|
|
if (!ref || s.id === 'earnerscorner') return href;
|
|
try { const u = new URL(href); u.searchParams.set(s.go ? 's1' : 'ref', ref); return u.toString(); } catch (e) { return href; }
|
|
}
|
|
function netLine(el) {
|
|
if (!el) return;
|
|
let list = NET, ref = '';
|
|
const paint = () => { el.innerHTML = '<b>Part of the network</b> · One account across the network: ' + list.map(s => (s.id === 'dlb' || /downlinebanners\.com/.test(s.url))
|
|
? '<span class="here" aria-current="page">' + esc(s.name) + '</span>' : '<a href="' + esc(netRef(s.go || s.url, s, ref)) + '" target="_blank" rel="noopener nofollow">' + esc(s.name) + '</a>').join(' · '); };
|
|
paint();
|
|
fetch('/api/network-sites').then(r => r.json()).then(l => { if (Array.isArray(l) && l.length) { list = l; paint(); } }).catch(() => {});
|
|
fetch('/api/me', { credentials: 'same-origin' }).then(r => r.json()).then(m => { const r = m && m.signedIn && okRef(m.username) ? m.username : (m && okRef(m.refName) ? m.refName : ''); if (r) { ref = r; paint(); } }).catch(() => {});
|
|
}
|
|
// one spot tile; href goes through the /go relay, which counts the click
|
|
function tile(t, opts) {
|
|
const a = document.createElement('a');
|
|
a.className = 'lot' + (t.t !== 'spot' ? ' house' : '');
|
|
a.href = t.href; a.target = '_blank'; a.rel = 'noopener';
|
|
const img = document.createElement('img'); img.src = t.img; img.width = 468; img.height = 60; img.alt = t.t === 'spot' ? 'Spot #' + t.id : (t.title || 'Network');
|
|
img.loading = 'lazy'; img.referrerPolicy = 'no-referrer';
|
|
img.onerror = () => { img.onerror = null; img.src = '/art/house-line.svg'; };
|
|
a.appendChild(img);
|
|
if (opts && opts.meta) { const m = document.createElement('span'); m.className = 'lot-meta'; m.textContent = t.t === 'spot' ? '#' + t.id : 'network'; a.appendChild(m); }
|
|
return a;
|
|
}
|
|
// live sale toasts (Marty 2026-11-13): real sales from the ledger only, bottom-left, one at a time, never older than 30 minutes
|
|
let toastsOn = false;
|
|
async function toasts() {
|
|
if (toastsOn) return; toastsOn = true;
|
|
const seen = new Set(); let first = true;
|
|
const box = document.createElement('div'); box.className = 'bl-toasts'; box.setAttribute('aria-live', 'polite'); document.body.appendChild(box);
|
|
const show = it => {
|
|
const top = it.pays.filter(p => !p.failed).sort((a, b) => (BigInt(b.wei) > BigInt(a.wei) ? 1 : -1))[0];
|
|
const name = it.ownerName ? '@' + esc(it.ownerName) : esc(String(it.owner || '').slice(0, 6) + '...' + String(it.owner || '').slice(-4)); // never a blank buyer (Marty 2026-11-14)
|
|
const el = document.createElement('a'); el.className = 'bl-toast'; el.href = '/ledger';
|
|
el.innerHTML = '<b>' + name + '</b> took spot #' + it.spotId
|
|
+ (top ? '<br><span>' + (it.pays.length > 1 ? it.pays.length + ' members paid, ' : '') + (top.name ? '@' + esc(top.name) : 'a member') + ' got ' + fmtPol(top.wei, 2) + ' POL</span>' : '<br><span>paid on-chain, $5</span>');
|
|
box.appendChild(el); requestAnimationFrame(() => el.classList.add('in'));
|
|
setTimeout(() => { el.classList.remove('in'); setTimeout(() => el.remove(), 400); }, 7000);
|
|
};
|
|
const tick = async () => {
|
|
let d; try { d = await getJSON('/api/ledger?n=5'); } catch (e) { return; } if (!d || !d.items) return;
|
|
const fresh = d.items.filter(it => !seen.has(it.tx) && (!it.at || Date.now() - it.at < 30 * 60000));
|
|
d.items.forEach(it => seen.add(it.tx));
|
|
const list = first ? fresh.slice(0, 1) : fresh.reverse(); first = false;
|
|
list.forEach((it, i) => setTimeout(() => show(it), 1500 + i * 8000));
|
|
};
|
|
tick(); setInterval(tick, 25000);
|
|
}
|
|
// network ad zones (Marty 2026-11-13): LinkSpin zones on Marty's account, one per placement, mounted once (never re-rendered,
|
|
// so a view is counted once); a small 'Network' label so they never pass for a member's spot
|
|
const ZONES = { ledger: 'ls-d53e5d', footWide: 'ls-fd1e0a', footPhone: 'ls-46cbab', bought: 'ls-03783e', mySpots: 'ls-50eaeb', how: 'ls-79e849', contract: 'ls-bd7632' };
|
|
function zone(el, key) {
|
|
if (!el || el.dataset.zoned || !ZONES[key]) return; el.dataset.zoned = '1'; el.classList.add('bl-zone');
|
|
const lab = document.createElement('div'); lab.className = 'bl-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 withRef(href, sponsor) { if (!sponsor) return href; return href + (href.includes('?') ? '&' : '?') + 'ref=' + encodeURIComponent(sponsor); }
|
|
return { $, esc, getConfig, fmtPol, short, framed, status, getJSON, post, renderNav, renderFooter, tile, withRef, zone };
|
|
})();
|
|
// 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 (traffic-exchange views).
|
|
(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', 'dlb'); document.head.appendChild(s);
|
|
})();
|