From 18e9c5d56ab738fbeebcc1742c6cf4a29a39bb71 Mon Sep 17 00:00:00 2001 From: martbost Date: Tue, 17 Nov 2026 07:26:58 -0600 Subject: [PATCH] Network Weekend (Marty 2026-11-17): ribbon + date-gated chatbot fact (any IAP $10+ pack unlocks Stack POL Pro) netdeals.js + /assets/netweekend.js (/api/network-deals from the hub), loaded on every page by layout.js. FACTS line live Fri 11-27 00:00 CT to Tue 12-01 00:00 CT (WEEKEND_NOW test clock). Co-Authored-By: Claude Opus 5.5 --- chatbot.js | 9 +++-- layout.js | 2 +- netdeals.js | 54 ++++++++++++++++++++++++++++++ public/assets/netweekend.js | 67 +++++++++++++++++++++++++++++++++++++ server.js | 1 + 5 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 netdeals.js create mode 100644 public/assets/netweekend.js diff --git a/chatbot.js b/chatbot.js index 708719f..0a89d67 100644 --- a/chatbot.js +++ b/chatbot.js @@ -13,7 +13,11 @@ const core = require('./chatcore'); const { PROGRAMS } = require('./programs'); -const KNOWLEDGE_DATE = '2026-11-15'; +const KNOWLEDGE_DATE = '2026-11-17'; +// Network Weekend (Black Friday to Cyber Monday 2026): live Fri 11-27 00:00 CT to Tue 12-01 00:00 CT (CST = UTC-6); WEEKEND_NOW = test clock +const NW_START = Date.parse('2026-11-27T06:00:00Z'), NW_END = Date.parse('2026-12-01T06:00:00Z'); +const nwNow = () => { const t = process.env.WEEKEND_NOW ? Date.parse(process.env.WEEKEND_NOW) : NaN; return Number.isNaN(t) ? Date.now() : t; }; +const nwLive = () => { const t = nwNow(); return t >= NW_START && t < NW_END; }; const URL_ = String(process.env.SITE_URL || 'https://stackpol.com').replace(/\/+$/, ''); const SUPPORT = 'https://instantadpay.com/support'; const NAMES = PROGRAMS.map(p => p.n).join(', '); @@ -61,9 +65,10 @@ const FAQ = [ const FACTS = () => [ '- WHAT IT IS: Stack POL (' + URL_ + ') adds up every POL payout across the network: ' + NAMES + '. Front page = everyone combined (network totals, last 7 days, latest payouts), /programs, /earn/ pages, /ledger (filter ?p=), opt-in member pages ' + URL_ + '/, /blog. It sells nothing and holds nothing: every payment goes from the program straight to the member\'s wallet on Polygon.', '- DATA: each program\'s payout records and the network contracts on Polygon, refreshed every 5 minutes; every ledger row links to its Polygon transaction. Members are named only when they switch on "Show my Stack POL page" in InstantAdPay Promo tools (join InstantAdPay free and link a wallet first).', + (nwLive() ? '- NETWORK WEEKEND (live now, Black Friday to Cyber Monday, Fri 11-27 to Mon 11-30, midnight to midnight Central): Stack POL sells nothing itself. Its Pro view unlocks with any InstantAdPay package of $10 or more (an existing perk, not a weekend price), so a $10+ InstantAdPay pack this weekend also unlocks Stack POL Pro. Every network deal: https://instantadpay.com/weekend. Ad credits buy advertising, not income.' : null), '- NEVER quote a total as what someone will earn; never state a maximum. ' + NOT_INCOME, '- For how a program pays (prices, splits, rules), use that program\'s own knowledge-base entries and send people to that site. SUPPORT: network support at ' + SUPPORT + '.' -].join('\n'); +].filter(Boolean).join('\n'); const SITE = { id: 'stackpol', hubSite: 'stackpol', netId: 'stackpol', name: 'Stack POL', url: URL_, supportUrl: SUPPORT, knowledgeDate: KNOWLEDGE_DATE, diff --git a/layout.js b/layout.js index 0fd6de3..4fb22c8 100644 --- a/layout.js +++ b/layout.js @@ -177,6 +177,6 @@ function tail(extra) { + '

© ' + year + ' Stack POL by TrustClickz. Part of the Crypto Team Build Network. Stack POL shows payouts; it does not hold, invest or pay out anyone\'s money.

' // PolHunter mission (Marty 2026-11-10): silent unless a hunter arrives with their own #ph token; the code lands on one of the // program cards (3 slots, which one rotates per hunter per day) - + '' + (extra || '') + SPOT_JS + ''; + + '' + (extra || '') + SPOT_JS + ''; } module.exports = { SITE, esc, head, tail, OG, V, ZONES, spot, personalize, memberLinks, proCta, MEMBER_HOST }; diff --git a/netdeals.js b/netdeals.js new file mode 100644 index 0000000..e708583 --- /dev/null +++ b/netdeals.js @@ -0,0 +1,54 @@ +// 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). +function handle(req, res, self) { + 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/assets/netweekend.js b/public/assets/netweekend.js new file mode 100644 index 0000000..7bbb5d3 --- /dev/null +++ b/public/assets/netweekend.js @@ -0,0 +1,67 @@ +// "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]) || ''; + var onDealsPage = ev.url && (location.origin + location.pathname) === ev.url; + 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/server.js b/server.js index 17c4d1e..9863ed6 100644 --- a/server.js +++ b/server.js @@ -210,6 +210,7 @@ const server = http.createServer((req, res) => { if (p.startsWith('/api/chat') || p.startsWith('/api/admin/kb')) { chatbot.handle(req, res, p, u, { json: chatJson, readBody: chatBody, isAdmin: () => false }) .then(done => { if (!done) chatJson(res, 404, { error: 'Not found' }); }).catch(e => { console.error('[stackpol] chat', e.message); if (!res.headersSent) chatJson(res, 500, { error: 'Server error' }); }); return; } if (req.method !== 'GET' && req.method !== 'HEAD') { res.writeHead(405); return res.end(); } + if (p === '/api/network-deals' && req.method === 'GET') return require('./netdeals').handle(req, res, 'stackpol'); // Network Weekend ribbon (2026-11-17) if (p === '/api/totals') return send(req, res, 200, 'application/json', JSON.stringify({ at: IDX ? IDX.at : null, network: net(), programs: (IDX && IDX.programs) || {} }), 'public, max-age=120'); if (p === '/health') return send(req, res, 200, 'text/plain', 'ok', 'no-store'); // ?ref= of a Pro member (Marty 2026-11-09): every call to action credits them (join links, game links, program