cf0da5044a
Config default, compose default, page fallbacks, FAQ/guide copy, sprout-meter fallback, asset version bump. Spotlight $10 / 1,000 views and the 20/5/5/5/5/60 split marked approved as built. unit 35/35, e2e 124/124. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
144 lines
15 KiB
JavaScript
144 lines
15 KiB
JavaScript
// Shared page helpers (YPB namespace, the network common.js pattern): header, footer (legal, company line, the network line from the
|
|
// hub), verified visits, seed-packet cards, toasts of real events, the network ad zones, small formatters. The look lives in ypb.css.
|
|
window.YPB = (function () {
|
|
let cfgP = null, vt = null;
|
|
const I = window.YPBI || {};
|
|
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);
|
|
const month = t => t ? new Date(t).toLocaleDateString('en-US', { timeZone: 'America/Chicago', month: 'short', day: 'numeric' }).toUpperCase() : '';
|
|
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"><rect x="1" y="1" width="32" height="32" rx="8" fill="var(--leaf)"/><path d="M17 27V15" stroke="var(--paper)" stroke-width="3" stroke-linecap="round"/><path d="M17 17c0-5 4-8 9-8 0 5-4 8-9 8z" fill="var(--butter)"/><path d="M17 20c0-4-3-6-8-6 0 4 3 6 8 6z" fill="var(--paper)"/></svg>';
|
|
function renderNav(active) {
|
|
const h = document.createElement('header'); h.className = 'top wrap';
|
|
const links = [['/', 'Seed Bed'], ['/my?tab=plant', 'Plant a program'], ['/transplanted', 'Transplanted'], ['/spotlight', 'Spotlight'], ['/guides', 'Guides'], ['/my', 'My packets']];
|
|
h.innerHTML = '<a class="skip" href="#main">Skip to content</a><a class="brand" href="/" aria-label="YourProgramBuilder, the Seed Bed">' + MARK + '<span>YourProgramBuilder</span></a>'
|
|
+ '<nav class="links" aria-label="Main">' + links.map(l => '<a href="' + l[0] + '"' + (l[0] === active ? ' aria-current="page"' : '') + '>' + l[1] + '</a>').join('') + '</nav>'
|
|
+ '<a class="signin" id="navSign" href="/my">Sign in with the network</a>';
|
|
document.body.prepend(h);
|
|
getConfig().then(c => { if (c.staging) { const b = document.createElement('div'); b.className = 'stage-bar wrap'; b.textContent = 'Staging copy for testing. No payouts, no mail, no contract: nothing here is real money.'; 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'; });
|
|
}
|
|
// the click relay: placement + the visitor's verified token once their visit has verified (+ the member whose page this is)
|
|
const goHref = (id, p, r) => '/go/' + id + '?p=' + encodeURIComponent(p || 'site') + (r ? '&r=' + encodeURIComponent(r) : '') + (vt ? '&v=' + vt : '');
|
|
function decorate() { document.querySelectorAll('a[data-go]').forEach(a => { a.href = goHref(a.dataset.go, a.dataset.p, a.dataset.r); }); }
|
|
const stageTag = x => x.stage === 'approved' ? '<span class="tag ok">Transplanted</span>' : x.stage === 'review' ? '<span class="tag ok">Ready for review</span>' : '';
|
|
// a seed packet. o = { place, r (member), spot, extra (html) }
|
|
function packetCard(x, o) {
|
|
o = o || {}; const spot = o.spot || !!x.spotlight;
|
|
const pctv = Math.min(100, Math.round(100 * (x.saves || 0) / (x.need || 10)));
|
|
const tags = [];
|
|
if (x.spotlight) tags.push('<span class="tag sp">Spotlight ' + n(x.spotlight.delivered) + ' / ' + n(x.spotlight.views) + ' views</span>');
|
|
tags.push(stageTag(x));
|
|
if (x.check === 'green') tags.push('<span class="tag ok">Link checked</span>');
|
|
tags.push('<span class="tag">' + (x.cost === 'free' ? 'Free to join' : esc(x.costText || 'Paid')) + '</span>');
|
|
if (x.contract) tags.push('<span class="tag">Contract listed</span>');
|
|
const by = x.mine ? 'your ID is saved' : x.own ? 'you planted this' : x.stage === 'review' ? 'in Marty\'s review queue' : x.planter ? 'planted by @' + esc(x.planter) : 'sponsor link first';
|
|
return '<article class="pk' + (spot ? ' spotlit' : '') + '"><div class="fold"></div><div class="body">'
|
|
+ '<div class="no"><span>PACKET No. ' + esc(x.no) + ' · SOWN ' + esc(month(x.sownAt)) + '</span>' + (I.iconOrganic || '') + '</div>'
|
|
+ '<div class="meta">' + tags.filter(Boolean).join('') + '</div>'
|
|
+ '<h3><a href="/p/' + x.id + (o.r ? '?r=' + encodeURIComponent(o.r) : '') + '">' + esc(x.name) + '</a></h3><p>' + esc(x.desc) + '</p>'
|
|
+ '<div class="meter"><div class="lbl"><span>Saved IDs</span><span>' + n(x.saves) + ' / ' + n(x.need) + '</span></div><div class="bar" role="img" aria-label="' + n(x.saves) + ' of ' + n(x.need) + ' saved IDs"><span style="width:' + pctv + '%"></span></div></div>'
|
|
+ '<div class="row"><a class="save' + (x.mine ? ' done' : '') + '" href="/p/' + x.id + (o.r ? '?r=' + encodeURIComponent(o.r) : '') + '#save">' + (I.iconSprout || '') + (x.mine ? 'ID saved' : 'Save my ID') + '</a>'
|
|
+ '<a class="by" data-go="' + x.id + '" data-p="' + esc(o.place || 'card') + '"' + (o.r ? ' data-r="' + esc(o.r) + '"' : '') + ' target="_blank" rel="noopener sponsored nofollow" href="' + goHref(x.id, o.place, o.r) + '">Visit ' + esc(x.host) + '</a></div>'
|
|
+ (o.extra || '') + '</div></article>';
|
|
}
|
|
// the page's data and its verified visit: packets come with a ticket; after visitSeconds of the page being visible the visit is sent once
|
|
async function wire(page, q) {
|
|
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) + (q || '') + (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('ypb:verified', { detail: r })); }
|
|
}, 500);
|
|
document.addEventListener('visibilitychange', () => { last = Date.now(); });
|
|
}
|
|
return d;
|
|
}
|
|
function spotRow(el, d, r) { if (!el) return; const f = d.spotlights || []; el.hidden = !f.length; if (f.length) el.querySelector('.bed').innerHTML = f.map(x => packetCard(x, { place: 'spot', spot: true, r })).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'], ['viraladsource', 'ViralAdSource', 'https://viraladsource.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: 'yourprogrambuilder', name: 'YourProgramBuilder', url: 'https://yourprogrambuilder.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 === 'yourprogrambuilder'
|
|
? '<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 === 'yourprogrambuilder') ? l : l.concat([HERE])); }).catch(() => {});
|
|
}
|
|
function renderFooter() {
|
|
const f = document.createElement('footer'); f.className = 'foot wrap';
|
|
f.innerHTML = '<p><b>YourProgramBuilder</b> The Seed Bed: bring your program, the network grows it. A directory of programs, not an income opportunity. Nothing is promised.</p>'
|
|
+ '<p><a href="/">Seed Bed</a><a href="/my?tab=plant">Plant a program</a><a href="/transplanted">Transplanted</a><a href="/spotlight">Spotlight</a><a href="/promote">Promote</a><a href="/guides">Guides</a><a href="/guides/faq">FAQ</a></p>'
|
|
+ '<p class="netline"></p>'
|
|
+ '<p>© 2026 TrustClickz <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=yourprogrambuilder" target="_blank" rel="noopener">Support</a></p>';
|
|
document.body.appendChild(f);
|
|
netLine(f.querySelector('.netline'));
|
|
toasts();
|
|
}
|
|
let toastsOn = false;
|
|
function toasts() {
|
|
if (toastsOn || /^\/admin/.test(location.pathname)) 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 === 'spotlight') { el.href = '/ledger'; el.innerHTML = '<b>' + who(c) + ' spotlighted ' + esc(c.packet || 'a packet') + '</b><br><span>split on chain by the contract</span>'; }
|
|
else if (c.kind === 'save') { el.href = '/p/' + c.id; el.innerHTML = '<b>' + who(c) + ' saved an ID</b><br><span>in ' + esc(c.packet) + '</span>'; }
|
|
else if (c.kind === 'review') { el.href = '/p/' + c.id; el.innerHTML = '<b>' + esc(c.packet) + ' is ready for review</b><br><span>enough members saved an ID</span>'; }
|
|
else { el.href = '/p/' + c.id; el.innerHTML = '<b>' + who(c) + ' planted a program</b><br><span>' + esc(c.packet) + '</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 text to copy it'; } } }
|
|
return { I, MARK, $, esc, getConfig, short, framed, status, getJSON, post, n, pct, usd, month, renderNav, renderFooter, packetCard, wire, spotRow, decorate, goHref, polOf, when, copy };
|
|
})();
|
|
// every page: header, footer and the numbers from /api/config
|
|
(function () {
|
|
const boot = () => {
|
|
YPB.renderNav(document.body.dataset.nav || ''); YPB.renderFooter();
|
|
document.querySelectorAll('[data-icon]').forEach(el => { const svg = YPB.I[el.dataset.icon]; if (svg) el.outerHTML = svg; });
|
|
YPB.getConfig().then(c => {
|
|
const lv = (c.split || {}).levelBps || []; const sp = c.spotlight || {};
|
|
const V = { need: String(c.reviewSaves), spotUsd: '$' + sp.usd, spotViews: YPB.n(sp.views), sponsor: YPB.pct(lv[0]), levels: lv.slice(1).map(YPB.pct).join(' / '), lvlEach: YPB.pct(lv[1]),
|
|
company: YPB.pct(10000 - lv.reduce((t, x) => t + x, 0)), recheck: String(c.recheckHours), deliverDays: String(sp.deliverDays), quota: String(c.plantQuota) };
|
|
document.querySelectorAll('[data-cfg]').forEach(el => { const k = el.dataset.cfg; if (V[k] != null) el.textContent = V[k]; });
|
|
// network ad zones (the ViralAdSource pattern): LinkSpin zones on Marty's LinkSpin account, ids from LS_ZONES (none until made)
|
|
const Z = c.zones || {}; if (!Z.footWide || /^\/admin/.test(location.pathname) || document.body.dataset.noZones) return;
|
|
const zone = (el, id) => { el.className = 'net-zone'; el.style.cssText = 'margin:18px auto;text-align:center;max-width:100%'; el.innerHTML = '<div style="font-size:11px;letter-spacing:1px;opacity:.7;margin-bottom:4px">Network</div>'; const s = document.createElement('script'); s.async = true; s.src = 'https://linkspin.app/z.js'; s.setAttribute('data-zone', id); el.appendChild(s); };
|
|
const za = document.createElement('div'); document.querySelector('footer.foot').before(za); zone(za, window.innerWidth >= 760 ? Z.footWide : (Z.footPhone || Z.footWide));
|
|
if (location.pathname === '/ledger' && Z.ledger) { const d = document.createElement('div'); const t = document.getElementById('ledgerBox'); if (t) { t.after(d); zone(d, Z.ledger); } }
|
|
}).catch(() => {});
|
|
};
|
|
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', boot); else boot();
|
|
})();
|
|
// Network Weekend ribbon: netweekend.js paints it only while a network event is live (dates from the hub through /api/network-deals)
|
|
(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', 'yourprogrambuilder'); document.head.appendChild(s);
|
|
})();
|