Files
martbost 3e0dee517d Network Weekend (Marty 2026-11-17): 2 free post credits a day Fri 11-27 00:00 CT to Tue 12-01 00:00 CT, live VBBShop SKU values on every page and in the chatbot, the network ribbon
weekend.js: the date gate (WEEKEND_NOW test clock), FREE_CREDITS_PER_DAY stays 1. chainskus.js: skus() read every 60 s, so the
$10 pack shows what the contract credits (50 once the owner signs setSku, 40 before or after). netdeals.js + /assets/netweekend.js:
/api/network-deals and the ribbon; the VBB line is built from live values and drops itself if there is nothing true to say.
chatcore render hook, chatbot FACTS/CANNED from live values with a dated weekend fact. qa/weekend.test.mjs 33 pass, chatbot 182, smoke 268.
common.js?v=10, my.js?v=6, packages.js?v=2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 07:26:05 -06:00

68 lines
5.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// "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
})();