218bb10145
- promodays.js: reusable date-to-percent bonus map (setting promoDays, kill switch promoDaysOn), once per tx via marks (MySQL): Fri 11-27 +40% $5+, Sat/Sun +20% $5+, Mon 11-30 +30% $20+. A mapped Friday is paid by friday.js at max(fridayBonusPct, day pct), one bonus per tx, Game Pass Friday perk intact; Five Dollar Friday +20% resumes 12-04 with no hand edits. - friday.js: Thanksgiving Thursday 18:00 CT notice + email carry the Black Friday copy (one message); Black Friday kickoff and wrap-up copy; /api/friday reports the day's real pct and name; IAP_TEST_NOW test clock (ignored in production). - Weekend Starter Bundle ($20+ in the window: LinkSpin code WEEKEND500 on a purchase notice) and Builder Bundle ($100+: notice + GET /api/network/weekend-builders for DownlineHydra, X-Weekend-Key = env WEEKEND_BUNDLE_KEY, constant-time compare). - promos.js: promo_codes.starts (dormant-until gate) for code NETWORKWEEKEND. - gamepass.js: tier passes paid by a package Fri 11-27 00:00 CT to Fri 12-04 00:00 CT get Explorer/Champion +15 days, Legend +60. - /weekend deals page (assets/weekend.js), Home strip + Overview card (assets/weekend-card.js), network ribbon (netdeals.js + assets/netweekend.js via common.js and netline.js), chatbot fact + answer date-gated. - Share hosts: /weekend, /friday and other page names are pages, not usernames (email links use instantadpay.link: instantadpay.com is still on the Spamhaus DBL, checked 11-17). - welcome.js says the day's real pct; common.js/netline.js/welcome.js ?v=20261117nw. - Tests: qa/promodays.test.cjs (12) + qa/weekend.e2e.mjs (18) at test clocks; bash qa/run.sh weekend; member walk clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
5.4 KiB
JavaScript
69 lines
5.4 KiB
JavaScript
// "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
|
||
})();
|