From b0629395773e99ef7bb69f44fd7b385fea1c64af Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 17 Nov 2026 07:39:47 -0600 Subject: [PATCH] Network Weekend (Marty 2026-11-17): Boost views from the live VABShop SKU on every page, quote and chatbot, the network ribbon chainskus.js reads skus(1) every 60 s and keeps C.boost in step (BOOST_VIEWS stays the normal 500 as normalViews), so a $5 Boost shows 750 once the owner signs setSku and 500 before or after; crediting already follows the Purchase event's views. common.js rewrites the pages' static '500 guaranteed views' copy to the live number only when the chain differs. weekend.js: the Fri 11-27 00:00 CT to Tue 12-01 00:00 CT gate (WEEKEND_NOW test clock) for the dated chatbot fact; the ribbon line (netdeals.setLocal) only exists while the chain really holds the weekend Boost. chatcore render hook, live intro. qa/weekend.test.mjs 18 pass, chatbot 206, smoke 197. common.js?v=9. Co-Authored-By: Claude Opus 5.5 --- chainskus.js | 42 +++++++++++++++++++++++ chatbot.js | 32 +++++++++++++---- chatcore.js | 8 +++-- netdeals.js | 55 ++++++++++++++++++++++++++++++ public/admin.html | 2 +- public/assets/common.js | 15 ++++++++ public/assets/netweekend.js | 68 +++++++++++++++++++++++++++++++++++++ public/boost.html | 2 +- public/contract.html | 2 +- public/disclaimer.html | 2 +- public/how.html | 2 +- public/index.html | 2 +- public/ledger.html | 2 +- public/member.html | 2 +- public/my.html | 2 +- public/privacy.html | 2 +- public/promote.html | 2 +- public/terms.html | 2 +- qa/weekend.test.mjs | 44 ++++++++++++++++++++++++ server.js | 6 ++++ weekend.js | 19 +++++++++++ 21 files changed, 292 insertions(+), 21 deletions(-) create mode 100644 chainskus.js create mode 100644 netdeals.js create mode 100644 public/assets/netweekend.js create mode 100644 qa/weekend.test.mjs create mode 100644 weekend.js diff --git a/chainskus.js b/chainskus.js new file mode 100644 index 0000000..c468f81 --- /dev/null +++ b/chainskus.js @@ -0,0 +1,42 @@ +// Live SKU values from the shop contract (VABShop: skus(sku) = usdCents, views, active) (Marty 2026-11-17, Network Weekend): every page, pack card and the chatbot show what the +// contract will really credit, so a late or early owner setSku never shows a wrong number. skus(sku) is read over CHAIN_RPC every +// 60 s in the background (never on a request); until the first read answers, or if the RPC is down, the env values stand. +// The crediting itself never depends on this: the watcher credits the Purchase event's own credits (shop.js apply). +'use strict'; +const { Interface } = require('ethers'); +const IFACE = new Interface(['function skus(uint256) view returns (uint64 usdCents, uint64 units, bool active)']); +const TTL = 60 * 1000; +let onRead = null; +let C = null, ids = [], live = new Map(), at = 0, timer = null, inflight = null; +async function read(sku) { + const ac = new AbortController(); const t = setTimeout(() => ac.abort(), 8000); t.unref && t.unref(); + try { + const j = await (await fetch(C.chainRpc, { method: 'POST', headers: { 'Content-Type': 'application/json' }, signal: ac.signal, + body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'eth_call', params: [{ to: C.contractAddress, data: IFACE.encodeFunctionData('skus', [sku]) }, 'latest'] }) })).json(); + if (j.error || !j.result || j.result === '0x') throw new Error('skus(' + sku + ') ' + (j.error ? j.error.message : 'empty')); + const r = IFACE.decodeFunctionResult('skus', j.result); + return { usdCents: Number(r[0]), units: Number(r[1]), active: !!r[2] }; + } finally { clearTimeout(t); } +} +function refresh() { + if (inflight || !C || !C.contractAddress || !C.chainRpc) return inflight || Promise.resolve(); + inflight = Promise.all(ids.map(async s => { try { live.set(s, await read(s)); } catch (e) {} })).then(() => { at = Date.now(); if (onRead) try { onRead(); } catch (e) {} }).finally(() => { inflight = null; }); + return inflight; +} +function init(cfg, skuIds, after) { + C = cfg; onRead = typeof after === 'function' ? after : null; ids = (skuIds || []).filter(n => Number.isSafeInteger(n) && n > 0); + if (timer) clearInterval(timer); + if (C.contractAddress && C.chainRpc && ids.length) { refresh(); timer = setInterval(refresh, TTL); timer.unref && timer.unref(); } +} +// { usdCents, units, active } as the contract holds it, or null (not read yet / RPC down) +function get(sku) { return live.get(Number(sku)) || null; } +// VAB: the Boost as the contract holds it right now. C.boost (the one config object every module shares) is kept in step after each +// read, so the pages, quotes, proof page and chatbot all say the live views; C.boost.normalViews keeps the BOOST_VIEWS env value. +function syncBoost(C) { + if (C.boost.normalViews == null) { C.boost.normalViews = C.boost.views; C.boost.normalUsd = C.boost.usd; } + const l = get(C.boost.sku); + if (l && l.active && l.units > 0 && l.usdCents > 0) { C.boost.views = l.units; C.boost.usd = l.usdCents / 100; } + else { C.boost.views = C.boost.normalViews; C.boost.usd = C.boost.normalUsd; } + return C.boost; +} +module.exports = { init, get, syncBoost, refresh, _set: (sku, v) => live.set(Number(sku), v), _clear: () => live.clear(), _state: () => ({ at, n: live.size }) }; diff --git a/chatbot.js b/chatbot.js index 43b9ee1..6040a01 100644 --- a/chatbot.js +++ b/chatbot.js @@ -13,7 +13,9 @@ const core = require('./chatcore'); const C = require('./config').get(); -const KNOWLEDGE_DATE = '2026-11-15'; +const KNOWLEDGE_DATE = '2026-11-17'; +const weekend = require('./weekend'); // Network Weekend (2026-11-17): dated fact, from the live chain Boost (C.boost follows chainskus.js) +if (C.boost.normalViews == null) { C.boost.normalViews = C.boost.views; C.boost.normalUsd = C.boost.usd; } // before the first chain read const URL_ = 'https://' + C.site; const SUPPORT = 'https://instantadpay.com/support'; const B = C.boost, SP = C.split; @@ -98,15 +100,33 @@ const FACTS = () => [ '- SPONSOR LINE: from the network hub (same sponsor as InstantAdPay/LinkSpin). On the first Boost the keeper signs the line and the contract records it link by link; a recorded link never changes. People without a wallet in the network are left out.', '- TRUST: ' + URL_ + '/ledger (every Boost, every level paid, who was passed over, delivery), ' + URL_ + '/contract (live contract facts), toasts of real events, a Telegram card per Boost. Terms ' + URL_ + '/terms, Earnings Disclaimer ' + URL_ + '/disclaimer, Privacy ' + URL_ + '/privacy. Run by TrustClickz.', '- PROMO: ' + URL_ + '/promote (links, creatives in every common size, copy, all with the member\'s network username). Old ViralAdBlitz referral links open the member\'s new page; old balances were not carried.', - '- NO REFUNDS: blockchain payments are final; views left on a removed ad\'s Boosts are not delivered or refunded. SUPPORT for account or purchase problems: network support at ' + SUPPORT + ' (InstantAdPay runs the one desk for every network site).' -].join('\n'); + '- NO REFUNDS: blockchain payments are final; views left on a removed ad\'s Boosts are not delivered or refunded. SUPPORT for account or purchase problems: network support at ' + SUPPORT + ' (InstantAdPay runs the one desk for every network site).', + weekendFact() +].filter(Boolean).join('\n'); + +// Network Weekend (Black Friday to Cyber Monday, Fri 11-27 00:00 CT to Tue 12-01 00:00 CT): only while it runs, and only the +// Boost the contract really sells right now +function weekendFact() { + if (!weekend.on()) return ''; + return '- NETWORK WEEKEND (Black Friday to Cyber Monday, midnight to midnight Central, ends Monday 11-30 at 11:59 PM Central): ' + + (weekend.bonus(C) ? 'a $' + B.usd + ' Boost carries ' + B.views + ' guaranteed views instead of ' + B.normalViews + ', same price, for Boosts bought during the weekend. ' : '') + + 'Other network deals: https://instantadpay.com/weekend'; +} +// instant answers carry the normal Boost views; at answer time say what the contract sells right now +function render(t) { + if (!weekend.bonus(C)) return t; + return String(t).replace(new RegExp('(^|[^0-9,.$])' + B.normalViews + '(?=( guaranteed| views))', 'g'), '$1' + B.views) + .replace(new RegExp('\\b(own|your) ' + B.normalViews + '\\b', 'g'), '$1 ' + B.views); +} const SITE = { id: 'viraladblitz', hubSite: 'viraladblitz', netId: 'viraladblitz', name: 'ViralAdBlitz', url: URL_, supportUrl: SUPPORT, knowledgeDate: KNOWLEDGE_DATE, - dataDir: C.dataDir, canned: CANNED, faq: FAQ, facts: FACTS, - intro: 'You are the assistant on ViralAdBlitz (' + URL_ + '), the network\'s text-ad site: one free text ad per network member that spreads five levels down their team, and a $' + B.usd + ' Boost for ' + B.views + ' guaranteed views. It is part of a network of sites that share one account.', + dataDir: C.dataDir, canned: CANNED, faq: FAQ, facts: FACTS, render, quickTopics: ['How does my ad spread?', 'What is a Boost?', 'Where does the $5 go?', 'What is DownlineHydra?'] }; function init() { return core.init(SITE); } -module.exports = { init, handle: core.handle, answer: core.answer, KNOWLEDGE_DATE, CANNED, FAQ, SITE }; +const INTRO = () => 'You are the assistant on ViralAdBlitz (' + URL_ + '), the network\'s text-ad site: one free text ad per network member that spreads five levels down their team, and a $' + B.usd + ' Boost for ' + B.views + ' guaranteed views. It is part of a network of sites that share one account.'; +// the intro follows the live Boost too (it was a string fixed at boot) +Object.defineProperty(SITE, 'intro', { enumerable: true, get: () => INTRO() }); +module.exports = { init, handle: core.handle, answer: core.answer, KNOWLEDGE_DATE, CANNED, FAQ, SITE, FACTS, render }; diff --git a/chatcore.js b/chatcore.js index df23ff4..724599e 100644 --- a/chatcore.js +++ b/chatcore.js @@ -28,6 +28,8 @@ function key() { try { return fs.readFileSync(path.join(S.dataDir, 'openrouter.key'), 'utf8').trim(); } catch (e) { return ''; } } const enabled = () => !!key(); +// optional per-site rewrite of an instant answer at answer time (2026-11-17, Network Weekend: live chain numbers and dated deals) +const R = t => { try { return S && typeof S.render === 'function' ? S.render(t) : t; } catch (e) { return t; } }; // CANNED + FAQ in the shape kb.js stores (order keeps the first-match-wins sequence) function seeds() { @@ -129,14 +131,14 @@ async function answerRaw(message, historyText) { if (hit && other.length && !hit.handoff) hit = null; } catch (e) { kbOk = false; console.error('kb fast path', e.message); } // a hand-off (support, one person's account problem) always answers from its exact pattern, before anything else - if (hit && hit.handoff) return { reply: hit.answer, canned: true, kb: hit.id, handoff: true }; + if (hit && hit.handoff) return { reply: R(hit.answer), canned: true, kb: hit.id, handoff: true }; // then meaning (2026-11-16, netkb.route): the hub's semantic match over the network KB answers, keeps or overrules the // pattern hit, and picks the prompt context. Hub or model slow or down: null, and the pattern + BM25 path below runs as before. let sem = null; if (kbOk) { try { sem = await netkb.route(msg, { fast: hit, own: await kb.own(), prefer: other }); } catch (e) { sem = null; } } if (sem) hit = sem.hit; - if (hit) return Object.assign({ reply: hit.answer, canned: true, kb: hit.id }, sem ? { via: sem.via } : {}, hit.handoff ? { handoff: true } : {}); - if (!kbOk) for (const c of S.canned) if (c.re && c.re.test(msg)) return Object.assign({ reply: c.a, canned: true }, c.handoff ? { handoff: true } : {}); + if (hit) return Object.assign({ reply: R(hit.answer), canned: true, kb: hit.id }, sem ? { via: sem.via } : {}, hit.handoff ? { handoff: true } : {}); + if (!kbOk) for (const c of S.canned) if (c.re && c.re.test(msg)) return Object.assign({ reply: R(c.a), canned: true }, c.handoff ? { handoff: true } : {}); let kbBlock = '', kbIds = [], hits = []; try { const query = msg.split(/\s+/).length < 4 && historyText ? msg + ' ' + String(historyText).slice(-200) : msg; diff --git a/netdeals.js b/netdeals.js new file mode 100644 index 0000000..f24c466 --- /dev/null +++ b/netdeals.js @@ -0,0 +1,55 @@ +// Network deals for this site's "Network Weekend" ribbon (Marty 2026-11-17). One source: the hub's public GET /v1/network-deals +// (HUB_URL). Cached 2 minutes, refreshed in the background, never waits on a slow hub (2.5 s timeout); hub down = no ribbon. +// The same file lives in every network site. Never RM Circle, never the games (the hub list never names them). +// The page (/assets/netweekend.js) switches the ribbon on and off by its own clock at startsAt / endsAt, so a cached copy never +// shows early or late. setLocal(fn) lets a site rewrite its own deal line from live data (for example a price read from chain), +// so the ribbon never shows a number the contract does not charge: fn(deal) returns the deal, a changed copy, or null to drop it. +const TTL = 2 * 60 * 1000; +let cache = { at: 0, body: { events: [] } }; +let inflight = null; +let local = null; + +const hubUrl = () => String(process.env.HUB_URL || 'https://hub.saasy.top').trim().replace(/\/+$/, ''); +const safeUrl = u => (/^https:\/\/[a-z0-9.-]+(\/[^\s"'<>]*)?$/i.test(String(u || '')) ? String(u) : ''); +const str = (v, n) => String(v == null ? '' : v).slice(0, n || 300); +function clean(j) { + if (!j || !Array.isArray(j.events)) return null; + return { events: j.events.slice(0, 5).filter(e => e && e.id && !Number.isNaN(Date.parse(e.startsAt)) && !Number.isNaN(Date.parse(e.endsAt))).map(e => ({ + id: str(e.id, 60), name: str(e.name, 60), tagline: str(e.tagline, 160), url: safeUrl(e.url), startsAt: e.startsAt, endsAt: e.endsAt, + days: e.days && typeof e.days === 'object' ? Object.fromEntries(Object.entries(e.days).slice(0, 20).map(([k, v]) => [str(k, 10), str(v, 40)])) : {}, + deals: (Array.isArray(e.deals) ? e.deals : []).slice(0, 40).map(d => { + const x = { site: str(d.site, 30), name: str(d.name, 80), url: safeUrl(d.url), text: str(d.text), endsAt: Number.isNaN(Date.parse(d.endsAt)) ? e.endsAt : d.endsAt }; + if (d.note) x.note = str(d.note, 120); + if (d.byDay && typeof d.byDay === 'object') x.byDay = Object.fromEntries(Object.entries(d.byDay).slice(0, 20).map(([k, v]) => [str(k, 10), str(v)])); + return x; + }) + })) }; +} +function refresh() { + if (inflight || process.env.NETWORK_DEALS_HUB === '0') return inflight; + const ac = new AbortController(); const t = setTimeout(() => ac.abort(), 2500); + inflight = fetch(hubUrl() + '/v1/network-deals', { signal: ac.signal }) + .then(r => (r.ok ? r.json() : null)) + .then(j => { const b = clean(j); if (b) cache = { at: Date.now(), body: b }; else cache.at = Date.now(); }) + .catch(() => { cache.at = Date.now() - TTL + 30 * 1000; }) // hub down: try again in 30 s, keep the last good copy + .finally(() => { clearTimeout(t); inflight = null; }); + return inflight; +} +function current() { if (Date.now() - cache.at > TTL) refresh(); return cache.body; } +function setLocal(fn) { local = typeof fn === 'function' ? fn : null; } +function withLocal(body, self) { + if (!local) return body; + return { events: body.events.map(e => Object.assign({}, e, { deals: e.deals.map(d => { + if (d.site !== self) return d; + try { const r = local(Object.assign({}, d)); return r === undefined ? d : r; } catch (err) { return d; } + }).filter(Boolean) })) }; +} +// GET /api/network-deals: public, short cache, the same answer on every page. self = this site's network id (NETWORK_SITE_ID). +async function handle(req, res, self) { + if (!cache.at) { try { await refresh(); } catch (e) {} } // first ask after a boot waits for the hub once (2.5 s cap) + const me = String(self || process.env.NETWORK_SITE_ID || '').trim().toLowerCase(); + const body = Object.assign({ self: me }, withLocal(current(), me)); + res.writeHead(200, { 'Content-Type': 'application/json; charset=utf-8', 'Cache-Control': 'public, max-age=60', 'X-Content-Type-Options': 'nosniff' }); + res.end(JSON.stringify(body)); +} +module.exports = { current, handle, refresh, setLocal, clean, _set: b => { cache = { at: Date.now(), body: clean(b) || { events: [] } }; } }; diff --git a/public/admin.html b/public/admin.html index 6266778..48a0b99 100644 --- a/public/admin.html +++ b/public/admin.html @@ -35,7 +35,7 @@

Old site links

JSON file {"oldrefs": {"old username": "network username"}} replaces the whole map.

- + diff --git a/public/assets/common.js b/public/assets/common.js index 730d4f9..f8a8e85 100644 --- a/public/assets/common.js +++ b/public/assets/common.js @@ -1,10 +1,25 @@ // Shared page helpers (VAB namespace, modelled on VBB / Downline Banners common.js): nav, the royal ticker, verified visits, // ad cards, the shared SVG bits of the daylight look (mark, network lines, green checks), footer (legal, company line, the network line from the hub), network ad zones and toasts of real events. window.VAB = (function () { + // Network Weekend ribbon (Marty 2026-11-17): netweekend.js paints itself only while a network event is live (exact Central times) + if (!/^\/admin/.test(location.pathname)) { const nw = document.createElement('script'); nw.src = '/assets/netweekend.js?v=20261117a'; nw.defer = true; nw.setAttribute('data-site', 'viraladblitz'); document.head.appendChild(nw); } 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())); + // the Boost's views as the contract holds them (Marty 2026-11-17, Network Weekend): when the owner has set a different number on + // chain than the normal one, the page's own copy ("500 guaranteed views") is rewritten to the live number; never the ribbon or ads + function liveViewsCopy() { + getConfig().then(c => { + const b = c && c.boost; if (!b || !b.normalViews || !b.views || b.views === b.normalViews) return; + const from = String(b.normalViews), to = Number(b.views).toLocaleString('en-US'); + const re2 = new RegExp('\\b(your )' + from + '\\b', 'g'); + const w = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, { acceptNode: t => (t.parentElement && t.parentElement.closest('.nw-ribbon,script,style,textarea,input,.vab-ad,.ad')) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT }); + const hits = []; while (w.nextNode()) { const t = w.currentNode; if (t.nodeValue.indexOf(from) >= 0) hits.push(t); } + hits.forEach(t => { t.nodeValue = t.nodeValue.replace(new RegExp('(^|[^0-9,.$])' + from + '(?=( guaranteed| GUARANTEED| views| VIEWS))', 'g'), '$1' + to).replace(re2, '$1' + to); }); + }).catch(() => {}); + } + if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', liveViewsCopy); else setTimeout(liveViewsCopy, 0); 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'); diff --git a/public/assets/netweekend.js b/public/assets/netweekend.js new file mode 100644 index 0000000..87cea2d --- /dev/null +++ b/public/assets/netweekend.js @@ -0,0 +1,68 @@ +// "Network Weekend" ribbon (Marty 2026-11-17): a thin bar at the top of every network site page while a network event is live. +// Data: /api/network-deals (netdeals.js, from the hub). Switches on and off by this page's own clock at the event's exact +// startsAt / endsAt (US Central midnights), so a cached feed never shows it early or late, and it takes itself down at endsAt on +// a page left open. Shows this site's own deal for today (byDay, Central date) and links to the full deals page. +// The same file lives in every network site. Never RM Circle, never the games. No inline styles (CSP): styles go through CSSOM. +// Test clock: window.__NW_NOW (ms) before this script runs; nothing else. +(function () { + if (window.__nwRibbon) return; window.__nwRibbon = 1; + var tag = document.currentScript; + var meAttr = (tag && tag.getAttribute('data-site')) || ''; + function now() { return typeof window.__NW_NOW === 'number' ? window.__NW_NOW : Date.now(); } + // late November is CST (UTC-6) for every date this ribbon covers + function ctDay(ms) { return new Date(ms - 6 * 3600 * 1000).toISOString().slice(0, 10); } + function closedKey(id, day) { return 'nw.closed.' + id + '.' + day; } + function isClosed(id, day) { try { return window.localStorage.getItem(closedKey(id, day)) === '1'; } catch (e) { return false; } } + function setClosed(id, day) { try { window.localStorage.setItem(closedKey(id, day), '1'); } catch (e) {} } + var bar = null; + function remove() { if (bar && bar.parentNode) bar.parentNode.removeChild(bar); bar = null; } + function paint(body) { + var me = meAttr || (body && body.self) || ''; + var t = now(); + var ev = ((body && body.events) || []).filter(function (e) { return t >= Date.parse(e.startsAt) && t < Date.parse(e.endsAt); })[0]; + if (!ev) { remove(); return false; } + var day = ctDay(t); + if (isClosed(ev.id, day)) { remove(); return true; } + var mine = (ev.deals || []).filter(function (d) { return d.site === me && t < Date.parse(d.endsAt || ev.endsAt); })[0]; + var line = mine ? ((mine.byDay && mine.byDay[day]) || mine.text) : ''; + var label = (ev.days && ev.days[day]) || ''; + if (label && line.indexOf(label + ': ') === 0) line = line.slice(label.length + 2); // "Black Friday, Black Friday: ..." reads once + var onDealsPage = !!ev.url && (function () { try { var u = new URL(ev.url); return location.pathname === u.pathname && (location.hostname === u.hostname || me === 'iap'); } catch (e) { return false; } })(); + remove(); + bar = document.createElement('div'); + bar.className = 'nw-ribbon'; bar.setAttribute('role', 'region'); bar.setAttribute('aria-label', ev.name); + bar.style.cssText = 'position:relative;z-index:50;display:flex;flex-wrap:wrap;gap:4px 12px;align-items:center;justify-content:center;padding:8px 40px 8px 16px;' + + 'background:#14161b;color:#f4f1e8;font:600 13.5px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;text-align:center;border-bottom:2px solid #f2c94c'; + // built node by node with CSSOM styles: no style attributes, so a strict CSP (style-src 'self') has nothing to block + function el(tagName, css, text) { var n = document.createElement(tagName); if (css) n.style.cssText = css; if (text) n.textContent = text; return n; } + var head = el('span'); head.appendChild(el('b', 'color:#f2c94c', ev.name)); if (label) head.appendChild(document.createTextNode(' · ' + label)); + bar.appendChild(head); + var body2 = el('span', 'font-weight:500', line || ev.tagline); + if (line && mine && mine.note) { body2.appendChild(document.createTextNode(' ')); body2.appendChild(el('span', 'opacity:.75', mine.note)); } + bar.appendChild(body2); + if (ev.url && !onDealsPage) { var a = el('a', 'color:#f2c94c;text-decoration:underline', 'See every deal'); a.href = ev.url; a.target = '_blank'; a.rel = 'noopener'; bar.appendChild(a); } + var x = el('button', 'position:absolute;right:8px;top:50%;transform:translateY(-50%);background:none;border:0;color:#f4f1e8;font-size:18px;line-height:1;cursor:pointer;padding:4px 8px', '×'); + x.type = 'button'; x.setAttribute('aria-label', 'Hide for today'); bar.appendChild(x); + bar.querySelector('button').addEventListener('click', function () { setClosed(ev.id, day); remove(); }); + document.body.insertBefore(bar, document.body.firstChild); + return true; + } + var feed = null, timer = null; + function schedule() { + clearTimeout(timer); if (!feed) return; + // wake at the next switch moment (start, end, a deal ending, the next Central midnight), at least once a minute + var t = now(), next = t + 60 * 1000; + (feed.events || []).forEach(function (e) { + [e.startsAt, e.endsAt].concat((e.deals || []).map(function (d) { return d.endsAt; })).forEach(function (s) { var x = Date.parse(s); if (x > t && x < next) next = x; }); + }); + timer = setTimeout(function () { if (typeof window.__NW_NOW === 'number') window.__NW_NOW += next - t; paint(feed); schedule(); }, Math.max(250, next - t)); + } + function run() { + fetch('/api/network-deals', { credentials: 'omit' }).then(function (r) { return r.ok ? r.json() : null; }).then(function (b) { + if (!b || !Array.isArray(b.events) || !b.events.length) return; + feed = b; paint(b); schedule(); + }).catch(function () {}); + } + if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', run); else run(); + window.__nwPaint = function (b) { feed = b; return paint(b); }; // tests +})(); diff --git a/public/boost.html b/public/boost.html index d1a9df0..3d9c263 100644 --- a/public/boost.html +++ b/public/boost.html @@ -67,7 +67,7 @@ - + diff --git a/public/contract.html b/public/contract.html index a32e0b0..807362c 100644 --- a/public/contract.html +++ b/public/contract.html @@ -44,7 +44,7 @@ - + diff --git a/public/disclaimer.html b/public/disclaimer.html index e2ee51f..1530cf7 100644 --- a/public/disclaimer.html +++ b/public/disclaimer.html @@ -33,7 +33,7 @@

Prices and taxes

Boosts are priced in US dollars and paid in POL, whose price moves. Anything you receive is in POL and its dollar value can change. You are responsible for any taxes on what you receive where you live.

Who to ask

TrustClickz. Network support.

- + diff --git a/public/how.html b/public/how.html index 922b3b1..b752aa6 100644 --- a/public/how.html +++ b/public/how.html @@ -129,7 +129,7 @@

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

- + diff --git a/public/index.html b/public/index.html index cffaa4b..a0c557b 100644 --- a/public/index.html +++ b/public/index.html @@ -95,7 +95,7 @@

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

- + diff --git a/public/ledger.html b/public/ledger.html index 4e3baf1..d2d4406 100644 --- a/public/ledger.html +++ b/public/ledger.html @@ -34,7 +34,7 @@

Levels follow the buyer's sponsor line. Someone who has not bought a Boost is passed over and their share goes up to the next person who has. Advertising, not income. Nothing is promised.

- + diff --git a/public/member.html b/public/member.html index e8d17d0..a33b8f0 100644 --- a/public/member.html +++ b/public/member.html @@ -42,7 +42,7 @@

Advertising, not income. Nothing is promised.

- + diff --git a/public/my.html b/public/my.html index ff917d6..910df0e 100644 --- a/public/my.html +++ b/public/my.html @@ -85,7 +85,7 @@ - + diff --git a/public/privacy.html b/public/privacy.html index b4b9e0e..9c0c281 100644 --- a/public/privacy.html +++ b/public/privacy.html @@ -34,7 +34,7 @@

Your choices

You can edit your ad at any time, or ask us to remove it and your account here. Records on the blockchain cannot be removed by anyone.

Contact

Questions, problems or a request about your data: network support (TrustClickz).

- + diff --git a/public/promote.html b/public/promote.html index b258bbc..ae93fb1 100644 --- a/public/promote.html +++ b/public/promote.html @@ -33,7 +33,7 @@

Loading the kit...

- + diff --git a/public/terms.html b/public/terms.html index f5e21ff..cf37c85 100644 --- a/public/terms.html +++ b/public/terms.html @@ -42,7 +42,7 @@

Limits

As far as the law allows, we are not responsible for losses caused by the blockchain, your wallet, the price of POL, third-party websites in ads, or events outside our control, and our total responsibility to you is limited to what you paid for the purchase in question. These terms are governed by the laws of the State of Alabama, USA.

Contact

Questions, problems or a request about your data: network support (TrustClickz).

- + diff --git a/qa/weekend.test.mjs b/qa/weekend.test.mjs new file mode 100644 index 0000000..ac2a581 --- /dev/null +++ b/qa/weekend.test.mjs @@ -0,0 +1,44 @@ +// Network Weekend checks (Marty 2026-11-17): node qa/weekend.test.mjs. No network: a stand-in Polygon RPC for skus(). +// Every date gate runs on the WEEKEND_NOW test clock, never the machine clock. +import http from 'node:http'; import os from 'node:os'; import fs from 'node:fs'; import path from 'node:path'; +import { createRequire } from 'node:module'; +const require = createRequire(import.meta.url); +const { Interface } = require('ethers'); +let pass = 0, fail = 0; const ok = (c, m) => { if (c) pass++; else { fail++; console.log('FAIL', m); } }; +process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'vabwk-')); delete process.env.DOCSTORE_URL; process.env.NETKB = '0'; delete process.env.OPENROUTER_API_KEY; +const I = new Interface(['function skus(uint256) view returns (uint64 usdCents, uint64 views, bool active)']); +const SKUS = { 1: [500, 500, true] }; let down = false; +const rpc = http.createServer((q, r) => { let b = ''; q.on('data', c => { b += c; }); q.on('end', () => { const j = JSON.parse(b); + if (down) { r.writeHead(500); return r.end('x'); } + const sku = Number(I.decodeFunctionData('skus', j.params[0].data)[0]); + r.setHeader('Content-Type', 'application/json'); r.end(JSON.stringify({ jsonrpc: '2.0', id: j.id, result: I.encodeFunctionResult('skus', SKUS[sku] || [0, 0, false]) })); }); }); +await new Promise(r => rpc.listen(0, r)); +process.env.CHAIN_RPC = 'http://127.0.0.1:' + rpc.address().port; process.env.CONTRACT_ADDRESS = '0x00000000000000000000000000000000000B0B05'; +const C = require('../config.js').get(); +const weekend = require('../weekend.js'); const chainskus = require('../chainskus.js'); const netdeals = require('../netdeals.js'); +const bot = require('../chatbot.js'); +const at = iso => { process.env.WEEKEND_NOW = iso; }; +const sync = async () => { await chainskus.refresh(); }; +chainskus.init(C, [C.boost.sku], () => chainskus.syncBoost(C)); chainskus.syncBoost(C); + +for (const [iso, want] of [['2026-11-26T23:59:59-06:00', false], ['2026-11-27T00:00:00-06:00', true], ['2026-11-30T23:59:59-06:00', true], ['2026-12-01T00:00:00-06:00', false]]) + { at(iso); ok(weekend.on() === want, 'on() at ' + iso); } + +await sync(); ok(C.boost.views === 500 && C.boost.normalViews === 500 && C.boost.usd === 5, 'chain 500: normal'); +const deal = { site: 'viraladblitz', name: 'ViralAdBlitz', text: 'hub text' }; +at('2026-11-27T00:03:00-06:00'); ok(weekend.dealLine(C, deal) === null, 'late signature: no ribbon line'); +ok(/NETWORK WEEKEND/.test(bot.FACTS()) && !/750/.test(bot.FACTS()), 'weekend fact says no 750 before the chain does'); +SKUS[1] = [500, 750, true]; await sync(); +ok(C.boost.views === 750 && C.boost.usd === 5 && C.boost.normalViews === 500, 'owner set 750: C.boost follows'); +ok(weekend.dealLine(C, deal).text === 'A $5 Boost carries 750 guaranteed views instead of 500.', 'ribbon line from chain'); +ok(/750 guaranteed views instead of 500/.test(bot.FACTS()) && /Boost for 750 guaranteed views/.test(bot.SITE.intro), 'facts + intro live'); +ok(/buys 750 guaranteed network views/.test(bot.render('A $5 Boost buys 500 guaranteed network views. Each adds its own 500 views.')) && /own 750 views/.test(bot.render('its own 500 views')), 'canned rendered live'); +ok(bot.render('Pick 1 to 10, $500 limit') === 'Pick 1 to 10, $500 limit', 'unrelated numbers untouched'); +down = true; await sync(); ok(C.boost.views === 750, 'RPC down: last good read'); down = false; +at('2026-12-01T00:00:00-06:00'); ok(!/NETWORK WEEKEND/.test(bot.FACTS()), 'Tuesday: no weekend fact'); +ok(/750/.test(bot.FACTS()), 'Tuesday before the revert is signed: the bot still says what the contract sells'); +SKUS[1] = [500, 500, true]; await sync(); ok(C.boost.views === 500 && bot.render('500 guaranteed views') === '500 guaranteed views', 'reverted: 500'); +netdeals.setLocal(x => weekend.dealLine(C, x)); netdeals._set({ events: [{ id: 'e', name: 'N', startsAt: '2026-11-27T06:00:00.000Z', endsAt: '2026-12-01T06:00:00.000Z', deals: [deal] }] }); +let body = ''; netdeals.handle({}, { writeHead() {}, end(s) { body = s; } }, 'viraladblitz'); ok(JSON.parse(body).events[0].deals.length === 0, 'feed drops the line when chain is normal'); +ok(!/\u2014/.test(bot.FACTS()), 'no em dashes'); +rpc.close(); console.log('weekend: ' + pass + ' passed, ' + fail + ' failed'); process.exit(fail ? 1 : 0); diff --git a/server.js b/server.js index 0be5871..99d3352 100644 --- a/server.js +++ b/server.js @@ -30,6 +30,9 @@ const hubevents = require('./hubevents'); // network hub hook (2026-11-16): sign const hubline = require('./hubline'); const proof = require('./proof'); const netsites = require('./netsites'); +const netdeals = require('./netdeals'); // Network Weekend ribbon feed from the hub (2026-11-17) +const weekend = require('./weekend'); // Network Weekend: what the ribbon and chatbot say, from live chain values +const chainskus = require('./chainskus'); // live VABShop Boost views/price for every page, quote and the chatbot (2026-11-17) const vabnas = require('./vabnas'); const lstrack = require('./lstrack'); const chatbot = require('./chatbot'); // the site assistant (2026-11-15): chatcore.js + kb.js + the network knowledge base (netkb.js) @@ -307,6 +310,7 @@ const server = http.createServer(async (req, res) => { if (p === '/api/ledger' && req.method === 'GET') return json(res, 200, proof.ledger(u.searchParams.get('n')), { 'Cache-Control': 'public, max-age=10' }); if (p === '/api/contract' && req.method === 'GET') { if (limited(req, 'contract', 600, 3600000)) return json(res, 429, { error: 'Too many requests' }); return json(res, 200, await proof.contract(), { 'Cache-Control': 'public, max-age=60' }); } if (p === '/api/network-sites' && req.method === 'GET') return netsites.handle(req, res); + if (p === '/api/network-deals' && req.method === 'GET') return netdeals.handle(req, res, 'viraladblitz'); // toasts: real events of the last 30 minutes (new ads, Boosts with the levels they paid) if (p === '/api/recent' && req.method === 'GET') { const cut = Date.now() - 30 * 60000; @@ -500,6 +504,8 @@ const server = http.createServer(async (req, res) => { shop.setAttach(rec => { wire.attach(rec); store.bump('boosts', Number(rec.qty) || 1); }); shop.setHook(proof.onPurchase); shop.init(C); + chainskus.syncBoost(C); chainskus.init(C, [C.boost.sku], () => chainskus.syncBoost(C)); // C.boost follows the chain (2026-11-17) + netdeals.setLocal(d => weekend.dealLine(C, d)); vabnas.init({ boosts: () => wire.purchases(), remaining: b => wire.remaining(b), ad: id => store.ad(id) }); setInterval(() => { if (store.prune()) wire.rebuild(); }, 3600000).unref(); chatbot.init(); // after docstore.init: kb.json is a MySQL document diff --git a/weekend.js b/weekend.js new file mode 100644 index 0000000..ab396da --- /dev/null +++ b/weekend.js @@ -0,0 +1,19 @@ +// Network Weekend (Marty 2026-11-17): Black Friday to Cyber Monday 2026, Fri 11-27 00:00 CT to Tue 12-01 00:00 CT, exact instants +// (late November is CST, UTC-6). On this site the deal is the owner's VABShop setSku: a $5 Boost carries 750 views instead of 500. +// Nothing here changes what a Boost credits (the Purchase event's views do, shop.js); this only decides what the ribbon and the +// chatbot say, always from the live chain value (chainskus.js syncBoost), so a late or early signature never shows a wrong number. +// WEEKEND_NOW (ISO time) is the test clock: tests only, never set it on the server. +'use strict'; +const START = Date.parse('2026-11-27T06:00:00Z'); // Fri 11-27 00:00 CT +const END = Date.parse('2026-12-01T06:00:00Z'); // Tue 12-01 00:00 CT +function now() { const o = process.env.WEEKEND_NOW; const t = o ? Date.parse(o) : NaN; return Number.isNaN(t) ? Date.now() : t; } +function on(ms) { ms = ms == null ? now() : ms; return ms >= START && ms < END; } +// more views than normal on chain right now (the owner has switched the SKU) +const bonus = C => C.boost.normalViews != null && C.boost.views > C.boost.normalViews; +// the ribbon's ViralAdBlitz line: only when the chain really holds the weekend Boost; otherwise no line rather than a wrong one +function dealLine(C, d) { + if (!bonus(C)) return null; + const x = Object.assign({}, d, { text: 'A $' + C.boost.usd + ' Boost carries ' + C.boost.views.toLocaleString('en-US') + ' guaranteed views instead of ' + C.boost.normalViews.toLocaleString('en-US') + '.' }); + delete x.byDay; return x; +} +module.exports = { START, END, now, on, bonus, dealLine };