18aabb3cb2
The first deploy shipped the status strip stuck on Checking: the site CSP has no unsafe-inline, so the inline script never ran. Moved to /assets/friday.js. The sitemap list lives in blog.js, not the pages list I edited in server.js; /friday is in it now. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
38 lines
2.2 KiB
JavaScript
38 lines
2.2 KiB
JavaScript
/* /friday status strip (Marty, 2026-09-25). External file on purpose: the site's CSP blocks
|
|
inline scripts, which is how the first deploy shipped a strip stuck on "Checking". */
|
|
(function () {
|
|
var el = document.getElementById('frState');
|
|
if (!el) return;
|
|
function n(x) { return Number(x || 0).toLocaleString('en-US'); }
|
|
// the minute (Central) when the next Friday starts, found by scanning rather than assumed,
|
|
// so a daylight-saving change cannot put the countdown an hour out
|
|
function startsAt(dayKey) {
|
|
var now = Date.now();
|
|
for (var m = 0; m < 8 * 1440; m++) {
|
|
var t = now + m * 60000;
|
|
var d = new Date(t).toLocaleDateString('en-CA', { timeZone: 'America/Chicago' });
|
|
if (d === dayKey) return t;
|
|
}
|
|
return null;
|
|
}
|
|
function render(f) {
|
|
if (!f || !f.on) { el.innerHTML = '<span class="fr-tag">Paused</span><span>Five Dollar Friday is not running right now. Join free and you will hear when it is back.</span>'; return; }
|
|
if (f.live) {
|
|
var t = f.today || {};
|
|
el.className = 'fr-state live';
|
|
el.innerHTML = '<span class="fr-tag">Live now</span><span><b>It is Five Dollar Friday.</b> Bonus runs until midnight Central.</span>'
|
|
+ '<span><span class="fr-num">' + n(t.packs) + '</span> pack' + (t.packs === 1 ? '' : 's') + ' so far today</span>'
|
|
+ '<span><span class="fr-num">' + n(t.bonusCredits) + '</span> bonus credits issued</span>';
|
|
return;
|
|
}
|
|
var at = f.nextFriday ? startsAt(f.nextFriday) : null;
|
|
var left = at ? Math.max(0, at - Date.now()) : 0;
|
|
var hrs = Math.floor(left / 3600000), mins = Math.floor((left % 3600000) / 60000), days = Math.floor(hrs / 24);
|
|
var when = at ? (days >= 1 ? days + ' day' + (days === 1 ? '' : 's') + ' ' + (hrs % 24) + 'h' : hrs + 'h ' + mins + 'm') : '';
|
|
el.className = 'fr-state';
|
|
el.innerHTML = '<span class="fr-tag">Next</span><span><b>Next Five Dollar Friday: ' + (f.nextLabel || f.nextFriday || 'soon') + '.</b> Starts at midnight Central' + (when ? ', in ' + when : '') + '.</span>'
|
|
+ '<span>Join now so your account is ready before it starts.</span>';
|
|
}
|
|
fetch('/api/friday').then(function (r) { return r.ok ? r.json() : null; }).catch(function () { return null; }).then(render);
|
|
})();
|