// 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'], ['/join', 'Get a spot'], ['/my', 'My Spots']]; n.innerHTML = '
' + '
'; document.body.prepend(n); if (c && c.chainId && c.chainId !== 137) { const r = document.createElement('div'); r.className = 'rehearsal'; r.innerHTML = 'Rehearsal: 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 f = document.createElement('footer'); f.className = 'bl-foot'; f.innerHTML = '

Part of the Crypto Team Build Network

' + '

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.

' + '

How it works · Board · My Spots

'; document.body.appendChild(f); } // 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; } 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 }; })();