Dayparting + automatic destination health checks for the rotator

Hours: rotation.hours / destination.hours = null (always on) or 7 strings of 24 chars '1'/'0' (index 0 = Sunday); rotation.tz = IANA zone name or 'visitor' (country -> representative zone, Central when unknown). Outside the link's hours visitors go to the fallback (hit.oh = 1 so stats show it); a destination outside its own hours is skipped by the pick. Presets always/business/evenings/weekends, server-side validation of grid and zone (Intl), "my best hours" = top quarter of weekday-hour cells by uniques over 30 days, unlocks at 200 clicks.

Health (health.js): every 30 min each active destination and the fallback is fetched (10 s timeout, 5 redirects, HEAD then GET, 4 at a time) and classed ok / slow / dead / parked, with frameBlocked noted. Three failing checks in a row pause the destination (never the last live one of a rotation without a fallback); paused ones are re-checked every 6 h and come back after two clean passes only when LinkSpin paused them. Owner gets one on-site inbox notice per pause. POST /api/my/rotations/:id/health = Check now, once a minute.

Links screen: Hours chip + inline 7x24 editor (tap, drag to paint, presets, zone picker, plain-English summary, heat tint), per-destination clock button and chip, health dot + line per row, Check now button, auto-paused note.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-10 11:21:23 -05:00
parent 0938e89fbe
commit 97b206f3b5
5 changed files with 378 additions and 23 deletions
+103 -8
View File
@@ -7,6 +7,67 @@
const clicks7 = r => r.hits7 || 0;
const health = r => r.paused ? { cls: 'warn', t: 'PAUSED' } : !r.destinations.some(d => d.active) ? { cls: 'bad', t: 'NO LIVE DESTINATION' } : { cls: 'ok', t: 'LIVE' };
// ── dayparting: grid = 7 strings of 24 chars '1'/'0', index 0 = Sunday; null = always on ──
const ALL = '1'.repeat(24), NONE = '0'.repeat(24);
const rowOf = (a, b) => { let s = ''; for (let h = 0; h < 24; h++) s += h >= a && h < b ? '1' : '0'; return s; };
const PRESETS = { always: null, business: [NONE, rowOf(8, 18), rowOf(8, 18), rowOf(8, 18), rowOf(8, 18), rowOf(8, 18), NONE], evenings: new Array(7).fill(rowOf(17, 23)), weekends: [ALL, NONE, NONE, NONE, NONE, NONE, ALL] };
const ZONES = [['visitor', "Visitor's local time"], ['America/Chicago', 'Chicago (Central)'], ['America/New_York', 'New York (Eastern)'], ['America/Los_Angeles', 'Los Angeles (Pacific)'], ['Europe/London', 'London'], ['Europe/Berlin', 'Berlin'], ['Asia/Kolkata', 'India'], ['Asia/Manila', 'Manila'], ['Asia/Singapore', 'Singapore'], ['Australia/Sydney', 'Sydney']];
const DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], ORDER = [1, 2, 3, 4, 5, 6, 0];
const ranges = s => { const out = []; let a = -1; for (let h = 0; h <= 24; h++) { const on = h < 24 && s[h] === '1'; if (on && a < 0) a = h; if (!on && a >= 0) { out.push(a + '-' + h); a = -1; } } return out.join(', '); };
function hoursText(hours) {
if (!hours || hours.every(s => s === ALL)) return 'Always on';
if (hours.every(s => s === hours[0])) return 'Every day ' + ranges(hours[0]);
const wk = [1, 2, 3, 4, 5], we = [0, 6], off = s => !s.includes('1');
if (wk.every(i => hours[i] === hours[1]) && we.every(i => off(hours[i]))) return 'Mon-Fri ' + ranges(hours[1]);
if (wk.every(i => off(hours[i])) && hours[0] === hours[6]) return 'Weekends' + (hours[6] === ALL ? '' : ' ' + ranges(hours[6]));
const n = hours.join('').split('1').length - 1; return 'Custom, ' + n + ' of 168 hours';
}
const tzText = tz => !tz || tz === 'visitor' ? "visitor's local time" : ((ZONES.find(z => z[0] === tz) || [])[1] || tz.split('/').pop().replace(/_/g, ' ')) + ' time';
const hoursChip = (hours, tz) => hoursText(hours) + (hours ? ', ' + tzText(tz) : '');
// the inline 7 x 24 editor. o = { hours, tz (undefined = no zone picker), heat (7x24 counts), best, onSave(hours, tz), onCancel }
function hoursEditor(host, o) {
let grid = (o.hours || new Array(7).fill(ALL)).map(s => s.split('')); let tz = o.tz || 'visitor';
const other = tz !== 'visitor' && !ZONES.some(z => z[0] === tz);
const max = o.heat ? Math.max(1, ...o.heat.map(d => Math.max(...d))) : 0;
host.innerHTML = '<div class="he">'
+ '<div class="he-presets"><span class="muted" style="font-size:11px">Presets</span>' + [['always', 'Always on'], ['business', 'Business, Mon-Fri 8-18'], ['evenings', 'Evenings, 17-23'], ['weekends', 'Weekends']].map(p => '<button class="btn sm" type="button" data-p="' + p[0] + '">' + p[1] + '</button>').join('')
+ '<button class="btn sm" type="button" data-p="best"' + (o.best && o.best.ready ? '' : ' disabled') + '>Use my best hours</button></div>'
+ (o.tz !== undefined ? '<div class="he-tz"><label class="lbl" style="margin:0">Time zone<select class="field" data-tz>' + ZONES.map(z => '<option value="' + z[0] + '"' + (z[0] === tz ? ' selected' : '') + '>' + esc(z[1]) + '</option>').join('') + '<option value="other"' + (other ? ' selected' : '') + '>Other (type a zone name)</option></select></label><input class="field mono" data-tzo type="text" placeholder="Area/City, like America/Denver"' + (other ? ' value="' + esc(tz) + '"' : ' hidden') + '></div>' : '<div class="muted" style="font-size:11px">Hours follow the link\'s time zone: ' + esc(tzText(o.rotTz)) + '.</div>')
+ '<div class="he-wrap"><div class="he-grid" data-grid><span></span>' + new Array(24).fill(0).map((_, h) => '<span class="hl">' + (h < 10 ? '0' + h : h) + '</span>').join('')
+ ORDER.map(wd => '<span class="dlb" data-day="' + wd + '" title="Flip the whole day">' + DAYS[wd] + '</span>' + new Array(24).fill(0).map((_, h) => '<span class="c" data-wd="' + wd + '" data-h="' + h + '"' + (o.heat && o.heat[wd][h] ? ' style="--heat:' + (0.12 + 0.55 * o.heat[wd][h] / max).toFixed(2) + '" title="' + o.heat[wd][h] + ' unique visitors, ' + DAYS[wd] + ' ' + h + ':00"' : ' title="' + DAYS[wd] + ' ' + h + ':00"') + '></span>').join('')).join('') + '</div></div>'
+ '<div class="he-sum" data-sum></div>'
+ '<div class="muted" style="font-size:11px" data-best>' + (o.best ? (o.best.ready ? 'Your best hours are the top quarter of weekday-hour cells by unique visitors over the last 30 days (' + fmt(o.best.hits) + ' clicks). Tinted cells show where your clicks land.' : '"Use my best hours" unlocks after ' + fmt(o.best.need) + ' clicks in 30 days; ' + fmt(o.best.hits) + ' so far.') : '') + '</div>'
+ '<div class="acts"><button class="btn pri" type="button" data-save>Save hours</button><button class="btn" type="button" data-cancel>Cancel</button><span class="muted" style="font-size:11px">Hours are 0 to 23; 8-18 means 8:00 up to 18:00.</span></div></div>';
const cells = {}; host.querySelectorAll('.c').forEach(c => { cells[c.dataset.wd + ':' + c.dataset.h] = c; if (o.heat && o.heat[c.dataset.wd][c.dataset.h]) c.classList.add('heat'); });
const paint = () => { for (const k in cells) { const [wd, h] = k.split(':'); cells[k].classList.toggle('on', grid[wd][h] === '1'); } const hs = grid.map(d => d.join('')); host.querySelector('[data-sum]').innerHTML = esc(hoursText(hs.every(s => s === ALL) ? null : hs)) + (o.tz !== undefined ? ' <small>' + esc(tzText(tz)) + '</small>' : ''); };
const set = (wd, h, v) => { grid[wd][h] = v; };
let painting = null;
const g = host.querySelector('[data-grid]');
const cellAt = e => { const el = document.elementFromPoint(e.clientX, e.clientY); return el && el.classList.contains('c') && g.contains(el) ? el : null; };
g.addEventListener('pointerdown', e => { const c = cellAt(e); if (!c) return; e.preventDefault(); painting = grid[c.dataset.wd][c.dataset.h] === '1' ? '0' : '1'; set(c.dataset.wd, c.dataset.h, painting); paint(); });
g.addEventListener('pointermove', e => { if (painting == null) return; const c = cellAt(e); if (c && grid[c.dataset.wd][c.dataset.h] !== painting) { set(c.dataset.wd, c.dataset.h, painting); paint(); } });
const stop = () => { painting = null; }; g.addEventListener('pointerup', stop); g.addEventListener('pointercancel', stop); g.addEventListener('pointerleave', stop);
host.querySelectorAll('.dlb').forEach(l => l.addEventListener('click', () => { const wd = l.dataset.day; const v = grid[wd].every(x => x === '1') ? '0' : '1'; grid[wd] = new Array(24).fill(v); paint(); }));
host.querySelectorAll('[data-p]').forEach(b => b.addEventListener('click', () => { const p = b.dataset.p; const src = p === 'best' ? (o.best && o.best.hours) : PRESETS[p]; grid = (src || new Array(7).fill(ALL)).map(s => s.split('')); paint(); }));
const sel = host.querySelector('[data-tz]'), oth = host.querySelector('[data-tzo]');
if (sel) { sel.addEventListener('change', () => { if (sel.value === 'other') { oth.hidden = false; oth.focus(); tz = oth.value.trim() || 'visitor'; } else { oth.hidden = true; tz = sel.value; } paint(); }); oth.addEventListener('input', () => { tz = oth.value.trim() || 'visitor'; paint(); }); }
host.querySelector('[data-save]').addEventListener('click', () => { const hs = grid.map(d => d.join('')); o.onSave(hs.every(s => s === ALL) ? null : hs, o.tz !== undefined ? tz : undefined); });
host.querySelector('[data-cancel]').addEventListener('click', () => o.onCancel && o.onCancel());
host.heState = () => ({ hours: grid.map(d => d.join('')), tz }); // so a redraw can keep unsaved taps
paint();
}
// ── health readouts ──
const ago = ts => { const s = Math.max(0, Math.round((Date.now() - ts) / 1000)); return s < 60 ? 'just now' : s < 3600 ? Math.round(s / 60) + ' min ago' : s < 86400 ? Math.round(s / 3600) + ' h ago' : Math.round(s / 86400) + ' d ago'; };
const mdy = ts => new Date(ts).toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
const healthCls = h => !h ? '' : h.state === 'ok' ? 'ok' : h.state === 'slow' ? 'warn' : 'bad';
function healthLine(d) {
const h = d.health; if (!h) return 'Not checked yet; the first check runs within 30 minutes';
if (d.autoPaused) return (h.state === 'parked' ? 'Parked page' : h.state === 'dead' ? 'Dead page' : 'Back up') + ', auto-paused ' + mdy(d.autoPaused) + (h.state === 'ok' || h.state === 'slow' ? ', resumes after ' + (2 - (h.passes || 0)) + ' more clean check' + (2 - (h.passes || 0) === 1 ? '' : 's') : ', checked again every 6 hours');
if (h.state === 'ok' || h.state === 'slow') return 'Checked ' + ago(h.checkedAt) + ', ' + h.code + ' in ' + fmt(h.ms) + ' ms' + (h.note ? ', ' + h.note : '');
return 'Checked ' + ago(h.checkedAt) + ', ' + (h.note || h.state) + (d.active ? ', strike ' + h.fails + ' of 3' + (h.fails >= 3 ? ', kept live' : ', pauses at 3') : '');
}
let HE = null; // the destination editor that is open: { rid, did }
async function load(keep) {
let r; try { r = await CR.get('/api/my/rotations'); } catch (e) { CR.sub('could not load'); return; }
ROT = (r.rotations || []).slice().sort((a, b) => clicks7(b) - clicks7(a)); HOSTS = r.hosts || [];
@@ -37,21 +98,36 @@
const h = health(r); $('dLive').innerHTML = '<span class="' + h.cls + '"><span class="dot"></span>' + h.t + '</span>';
$('pauseBtn').textContent = r.paused ? 'Resume' : 'Pause';
$('fallback').value = r.fallback || '';
const fh = r.fallbackHealth; $('fallbackHealth').textContent = r.fallback ? (fh ? 'Fallback checked ' + ago(fh.checkedAt) + ': ' + (fh.state === 'ok' || fh.state === 'slow' ? fh.code + ' in ' + fmt(fh.ms) + ' ms' : (fh.note || fh.state)) + (fh.frameBlocked ? ', blocks frames' : '') : 'Fallback not checked yet') : '';
$('hoursChip').textContent = hoursChip(r.hours, r.tz); $('hoursChip').classList.toggle('set', !!r.hours);
renderTiles(r, STATS[id]);
renderDest(r); renderShare(r);
renderDest(r); renderShare(r); renderRotHours(r, STATS[id]);
if (!quiet) window.scrollTo({ top: 0 });
loadStats(r.id);
}
function renderDest(r) {
const total = r.destinations.filter(d => d.active).reduce((n, d) => n + d.weight, 0) || 1;
$('destRows').innerHTML = r.destinations.length ? r.destinations.map(d => { const share = d.active ? Math.round(d.weight / total * 100) : 0;
return '<div class="rw" data-did="' + d.id + '"><div><div style="font-weight:700">' + esc(d.label || d.url.replace(/^https?:\/\//, '').slice(0, 60)) + '</div><div class="mono muted" style="font-size:11px;overflow-wrap:anywhere">' + esc(d.url) + '</div></div>'
const auto = r.destinations.filter(d => d.autoPaused);
const prevHost = $('destRows').querySelector('[data-he]'); const prev = prevHost && HE && Number(prevHost.dataset.he) === HE.did && prevHost.heState ? prevHost.heState() : null;
$('autoNote').hidden = !auto.length;
if (auto.length) $('autoNote').textContent = 'LinkSpin paused ' + (auto.length === 1 ? 'one destination' : auto.length + ' destinations') + ' automatically after three failed checks: ' + auto.map(d => (d.label || d.url.replace(/^https?:\/\//, '')).slice(0, 40)).join(', ') + '. It comes back on its own after two clean checks, or fix the address and press Resume.';
$('destRows').innerHTML = r.destinations.length ? r.destinations.map(d => { const share = d.active ? Math.round(d.weight / total * 100) : 0; const h = d.health;
return '<div class="rw" data-did="' + d.id + '"><div><div class="dl"><span class="hdot ' + healthCls(h) + '" title="' + esc(healthLine(d)) + '"></span><span style="font-weight:700">' + esc(d.label || d.url.replace(/^https?:\/\//, '').slice(0, 60)) + '</span>' + (d.hours ? '<button class="hchip set" type="button" data-hc="' + d.id + '" title="This destination has its own hours">' + esc(hoursText(d.hours)) + '</button>' : '') + (h && h.frameBlocked ? '<span class="tag warn" title="This page refuses to load inside a frame (X-Frame-Options or CSP). Traffic exchanges that frame your link will show it blank.">no frames</span>' : '') + '</div>'
+ '<div class="mono muted" style="font-size:11px;overflow-wrap:anywhere">' + esc(d.url) + '</div><div class="muted" style="font-size:11px" data-hl="' + d.id + '">' + esc(healthLine(d)) + '</div></div>'
+ '<div class="wrow"><div class="bar" style="width:70px"><i style="width:' + share + '%"></i></div><input class="field mono" type="number" min="1" max="100" value="' + d.weight + '" data-w="' + d.id + '" aria-label="Weight"><span class="mono muted" style="font-size:11px">' + share + '%</span></div>'
+ '<span class="r num">' + fmt(d.hits || 0) + '</span><span class="r num">' + fmt(d.uniques || 0) + '</span>'
+ '<span class="tag ' + (d.active ? 'ok' : 'dim') + '">' + (d.active ? 'LIVE' : 'PAUSED') + '</span>'
+ '<span style="display:flex;gap:6px;justify-content:flex-end"><button class="btn sm" type="button" data-t="' + d.id + '">' + (d.active ? 'Pause' : 'Resume') + '</button><button class="btn sm danger" type="button" data-x="' + d.id + '" aria-label="Remove">&times;</button></span></div>'; }).join('')
+ '<span class="tag ' + (d.active ? 'ok' : d.autoPaused ? 'bad' : 'dim') + '">' + (d.active ? 'LIVE' : d.autoPaused ? 'AUTO-PAUSED' : 'PAUSED') + '</span>'
+ '<span style="display:flex;gap:6px;justify-content:flex-end"><button class="btn sm" type="button" data-hc="' + d.id + '" title="Hours for this destination" aria-label="Hours for this destination"><svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg></button><button class="btn sm" type="button" data-t="' + d.id + '">' + (d.active ? 'Pause' : 'Resume') + '</button><button class="btn sm danger" type="button" data-x="' + d.id + '" aria-label="Remove">&times;</button></span></div>'
+ (HE && HE.rid === r.id && HE.did === d.id ? '<div class="rw edit" data-he="' + d.id + '"></div>' : ''); }).join('')
: '<div class="rw"><span class="muted">No destinations yet. Add the first page below; until then the link sends people to the fallback.</span></div>';
$('destFoot').textContent = 'weights are shares of the spin · fallback: ' + (r.fallback || 'none set') + ' · bots filtered on the server · one hop';
$('destFoot').textContent = 'weights are shares of the spin · fallback: ' + (r.fallback || 'none set') + ' · bots filtered on the server · one hop · health checked every 30 min';
const openEditor = did => { const d = r.destinations.find(q => q.id === did); if (!d) return; HE = { rid: r.id, did }; renderDest(r); };
$('destRows').querySelectorAll('[data-hc]').forEach(b => b.addEventListener('click', () => { if (HE && HE.rid === r.id && HE.did === Number(b.dataset.hc)) { HE = null; renderDest(r); } else openEditor(Number(b.dataset.hc)); }));
const heHost = $('destRows').querySelector('[data-he]');
if (heHost) { const d = r.destinations.find(q => q.id === Number(heHost.dataset.he)); const s = STATS[r.id];
hoursEditor(heHost, { hours: prev ? prev.hours : d.hours, rotTz: r.tz, heat: s && s.best ? s.best.cells : null, best: s && s.best, onCancel: () => { HE = null; renderDest(r); },
onSave: async hours => { try { await api('/api/my/rotations/' + r.id + '/dest/' + d.id, { hours }); HE = null; toast(hours ? 'Hours saved' : 'Destination is always on'); load(true); } catch (e) { toast(e.message, true); } } });
if (heHost.scrollIntoView) heHost.scrollIntoView({ block: 'nearest' }); }
$('destRows').querySelectorAll('[data-w]').forEach(i => i.addEventListener('change', async () => { try { await api('/api/my/rotations/' + r.id + '/dest/' + i.dataset.w, { weight: i.value }); toast('Weight saved'); load(true); } catch (e) { toast(e.message, true); } }));
$('destRows').querySelectorAll('[data-t]').forEach(b => b.addEventListener('click', async () => { const d = r.destinations.find(q => q.id === Number(b.dataset.t)); try { await api('/api/my/rotations/' + r.id + '/dest/' + d.id, { active: !d.active }); load(true); } catch (e) { toast(e.message, true); } }));
$('destRows').querySelectorAll('[data-x]').forEach(b => b.addEventListener('click', async () => { if (!await dialog({ title: 'Remove this destination?', text: 'Its click history stays in the stats.', ok: 'Remove', danger: true })) return; try { await api('/api/my/rotations/' + r.id + '/dest/' + b.dataset.x, { remove: true }); toast('Removed'); load(true); } catch (e) { toast(e.message, true); } }));
@@ -67,6 +143,19 @@
$('shareKit').innerHTML = kit.map(([t, body], i) => '<div class="panel" style="padding:10px 12px"><div style="display:flex;justify-content:space-between;align-items:center;gap:8px"><b>' + esc(t) + '</b><button class="btn sm" type="button" data-cp="' + i + '">Copy</button></div><div class="mono muted" style="font-size:12px;overflow-wrap:anywhere;margin-top:6px" id="kit-' + i + '">' + esc(body) + '</div></div>').join('');
$('shareKit').querySelectorAll('[data-cp]').forEach(b => b.addEventListener('click', () => CR.copy($('kit-' + b.dataset.cp).textContent)));
}
// the rotation's own hours editor on the Hours tab. Not redrawn while the member is mid-edit (the 60 s refresh would eat their taps).
let RH = null; // { rid, dirty }
function renderRotHours(r, s) {
const host = $('rotHours');
if (RH && RH.rid === r.id && RH.dirty && host.firstChild) return;
RH = { rid: r.id, dirty: false };
hoursEditor(host, { hours: r.hours, tz: r.tz || 'visitor', heat: s && s.best ? s.best.cells : null, best: s && s.best,
onCancel: () => { RH = null; renderRotHours(r, STATS[r.id]); },
onSave: async (hours, tz) => { try { await api('/api/my/rotations/' + r.id, { hours, tz }); RH = null; toast(hours ? 'Hours saved' : 'Link is always on'); load(true); } catch (e) { toast(e.message, true); } } });
host.addEventListener('pointerdown', () => { if (RH) RH.dirty = true; }, { once: true });
host.addEventListener('change', () => { if (RH) RH.dirty = true; }, { once: true });
$('offNote').textContent = s ? ((s.offHours ? fmt(s.offHours) + ' click' + (s.offHours === 1 ? '' : 's') + ' arrived outside the link\'s hours and went to the fallback (all time, ' + fmt(r.offHours30 || 0) + ' in 30 days).' : 'No clicks have gone to the off-hours fallback yet.')) : '';
}
const kv = rows => rows && rows.length ? rows.map(x => '<span style="overflow-wrap:anywhere">' + esc(x.k) + '</span><span class="bar"><i style="width:' + Math.round(x.n / (rows[0].n || 1) * 100) + '%"></i></span><span class="r num">' + fmt(x.n) + '</span>').join('') : '<span class="muted">nothing yet</span><span></span><span></span>';
function renderTiles(r, s) {
let series = null, delta = null;
@@ -84,7 +173,7 @@
async function loadStats(id) {
let s = STATS[id]; if (!s) { try { s = await CR.get('/api/my/rotations/' + id + '/stats'); } catch (e) { return; } STATS[id] = s; setTimeout(() => { delete STATS[id]; }, 60000); }
if (SEL !== id) return;
{ const r = ROT.find(x => x.id === id); if (r) renderTiles(r, s); }
{ const r = ROT.find(x => x.id === id); if (r) { renderTiles(r, s); if (!(RH && RH.rid === id && RH.dirty)) renderRotHours(r, s); } }
const hmax = Math.max(1, ...s.hours); $('hourBars').innerHTML = s.hours.map((n, i) => '<i class="' + (n >= hmax * 0.6 ? '' : 'dim') + '" style="height:' + Math.round(n / hmax * 100) + '%" title="' + i + ':00 · ' + n + '"></i>').join('');
$('srcRows').innerHTML = kv(s.source); $('geoRows').innerHTML = kv(s.country); $('subRows').innerHTML = kv(s.subs); $('convRows').innerHTML = kv(s.conversions);
const dev = s.device || []; const dt = dev.reduce((n, x) => n + x.n, 0) || 1; $('devRow').textContent = dev.length ? dev.map(x => x.k + ' ' + Math.round(x.n / dt * 100) + '%').join(' · ') : '';
@@ -128,7 +217,13 @@
$('addBtn').addEventListener('click', async () => { const r = ROT.find(x => x.id === SEL); if (!r) return; const url = $('addUrl').value.trim(); if (!url) { $('addUrl').focus(); return; } try { await api('/api/my/rotations/' + r.id + '/dest', { url, label: $('addLabel').value, weight: $('addWeight').value }); $('addUrl').value = ''; $('addLabel').value = ''; toast('Destination added'); load(true); } catch (e) { toast(e.message, true); } });
$('addUrl').addEventListener('keydown', e => { if (e.key === 'Enter') $('addBtn').click(); });
$('fallback').addEventListener('change', async () => { const r = ROT.find(x => x.id === SEL); if (!r) return; try { await api('/api/my/rotations/' + r.id, { fallback: $('fallback').value.trim() }); toast('Fallback saved'); load(true); } catch (e) { toast(e.message, true); } });
$('tabs').querySelectorAll('button').forEach(b => b.addEventListener('click', () => { $('tabs').querySelectorAll('button').forEach(x => x.classList.toggle('on', x === b)); ['dest', 'hours', 'sources', 'report', 'share'].forEach(t => { $('tab-' + t).hidden = t !== b.dataset.tab; }); }));
const showTab = name => { $('tabs').querySelectorAll('button').forEach(x => x.classList.toggle('on', x.dataset.tab === name)); ['dest', 'hours', 'sources', 'report', 'share'].forEach(t => { $('tab-' + t).hidden = t !== name; }); };
$('tabs').querySelectorAll('button').forEach(b => b.addEventListener('click', () => showTab(b.dataset.tab)));
$('hoursChip').addEventListener('click', () => { showTab('hours'); const h = $('rotHours'); if (h.scrollIntoView) h.scrollIntoView({ block: 'start', behavior: 'smooth' }); });
$('checkBtn').addEventListener('click', async () => { const r = ROT.find(x => x.id === SEL); if (!r) return; const b = $('checkBtn'); b.disabled = true; b.textContent = 'Checking';
try { const out = await api('/api/my/rotations/' + r.id + '/health'); const i = ROT.findIndex(x => x.id === r.id); if (i >= 0 && out.rotation) ROT[i] = out.rotation; const fresh = out.rotation || r; renderDest(fresh); select(r.id, true);
const bad = fresh.destinations.filter(d => d.health && (d.health.state === 'dead' || d.health.state === 'parked')).length; toast('Checked ' + fresh.destinations.length + ' destination' + (fresh.destinations.length === 1 ? '' : 's') + (bad ? ', ' + bad + ' failing' : ', all answering')); }
catch (e) { toast(e.message, true); } b.disabled = false; b.textContent = 'Check now'; });
$('pbNew').addEventListener('click', () => pbForm(null));
$('backBtn').hidden = !window.matchMedia('(max-width:760px)').matches;
CR.requireSession(() => { load(); loadPb(); setInterval(() => { if (!document.hidden) load(true); }, 60000); });
+28 -4
View File
@@ -23,7 +23,26 @@
.dhead{display:flex;align-items:center;gap:14px;padding:12px 24px;border-bottom:1px solid var(--line);background:var(--panel);flex-wrap:wrap}
.dhead h2{font-family:var(--display);font-size:24px;font-weight:700;letter-spacing:.02em;margin:0}
.dbody{padding:16px 24px;display:grid;gap:14px}
.dest .hd,.dest .rw{grid-template-columns:minmax(0,2fr) 150px 80px 80px 110px 90px}
.dest .hd,.dest .rw{grid-template-columns:minmax(0,2fr) 150px 80px 80px 110px 130px}
.dest .rw.edit{grid-template-columns:1fr;background:var(--panel-2)}
.dest .dl{display:flex;align-items:center;gap:6px;flex-wrap:wrap}
.hdot{display:inline-block;width:9px;height:9px;border-radius:50%;background:var(--line-strong);flex:none;vertical-align:middle}
.hdot.ok{background:var(--ok);box-shadow:0 0 0 2px rgba(14,138,92,.2)} .hdot.warn{background:#D98B0C;box-shadow:0 0 0 2px rgba(217,139,12,.2)} .hdot.bad{background:var(--bad);box-shadow:0 0 0 2px rgba(185,28,28,.2)}
.hchip{display:inline-flex;align-items:center;gap:5px;font-family:var(--mono);font-size:10px;font-weight:700;color:var(--ink-2);border:1px solid var(--line-strong);border-radius:999px;padding:2px 8px;white-space:nowrap;background:#fff;cursor:pointer;letter-spacing:.02em}
.hchip.set{color:var(--sig-2);border-color:rgba(255,106,26,.5);background:var(--sig-soft)}
.he{display:grid;gap:10px}
.he-presets{display:flex;gap:6px;flex-wrap:wrap;align-items:center}
.he-tz{display:flex;gap:8px;align-items:center;flex-wrap:wrap} .he-tz select{width:auto;min-width:180px} .he-tz input{width:200px}
.he-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch;padding-bottom:6px}
.he-grid{display:grid;grid-template-columns:36px repeat(24,22px);gap:2px;touch-action:pan-x;user-select:none;-webkit-user-select:none;width:max-content}
.he-grid .hl{font-family:var(--mono);font-size:9px;font-weight:700;color:var(--muted);text-align:center;align-self:end;line-height:1}
.he-grid .dlb{font-family:var(--mono);font-size:11px;font-weight:700;color:var(--ink-2);align-self:center;cursor:pointer}
.he-grid .c{width:22px;height:22px;border-radius:3px;background:var(--panel-2);border:1px solid var(--line);cursor:pointer;box-sizing:border-box}
.he-grid .c.heat{background:rgba(31,111,235,var(--heat))}
.he-grid .c.on{background:var(--sig);border-color:var(--sig-2)}
.he-sum{font-weight:700} .he-sum small{font-weight:500;color:var(--muted)}
.he .acts{display:flex;gap:8px;align-items:center;flex-wrap:wrap}
.note{border:1px solid rgba(194,65,12,.4);background:var(--warn-soft);color:var(--warn);border-radius:8px;padding:8px 12px;font-size:12px}
.wrow{display:flex;align-items:center;gap:8px} .wrow input{width:56px}
.empty{padding:40px 24px;color:var(--muted);text-align:center;display:grid;gap:10px;justify-items:center}
.two{display:grid;grid-template-columns:minmax(0,1fr) 320px;gap:16px}
@@ -52,7 +71,9 @@
<span class="code" id="dUrl"></span>
<button class="btn sm" type="button" id="copyBtn">Copy</button>
<span class="mono" id="dLive"></span>
<button class="hchip" type="button" id="hoursChip" title="Hours this link is on">Always on</button>
<span class="grow"></span>
<button class="btn sm" type="button" id="checkBtn" title="Check every destination right now">Check now</button>
<button class="btn sm" type="button" id="renameBtn">Rename</button>
<button class="btn sm" type="button" id="pauseBtn">Pause</button>
<button class="btn sm danger" type="button" id="delBtn">Delete</button>
@@ -67,6 +88,7 @@
<button type="button" data-tab="share">Share kit</button>
</div>
<div id="tab-dest">
<div class="note" id="autoNote" hidden style="margin-bottom:10px"></div>
<div class="tbl dest">
<div class="hd"><span>Destination</span><span>Weight</span><span class="r">Clicks</span><span class="r">Unique</span><span>Status</span><span></span></div>
<div id="destRows"></div>
@@ -81,11 +103,13 @@
<button class="btn pri" type="button" id="addBtn">Add</button>
</div>
<div class="muted">Macros in a destination are filled per visitor: <span class="mono">{clickid} {subid} {s1}…{s5} {source} {country} {device} {lsid}</span>. Example: <span class="mono">https://tracker.example/?cid={clickid}&amp;src={source}</span></div>
<label class="lbl">Fallback, used when every destination is paused or the link is paused<input class="field mono" id="fallback" type="url" placeholder="https://"></label>
<label class="lbl">Fallback, used when every destination is paused, the link is paused, or the link is outside its hours<input class="field mono" id="fallback" type="url" placeholder="https://"></label>
<div class="muted mono" id="fallbackHealth" style="font-size:11px"></div>
</div>
</div>
<div id="tab-hours" hidden>
<div class="panel"><h2>Clicks by hour, UTC, all time</h2><div class="bars" id="hourBars" style="grid-template-columns:repeat(24,minmax(0,1fr))"></div><div class="axis"><span>00</span><span>06</span><span>12</span><span>18</span><span>23</span></div><div class="muted">Hour rules (open a destination only at set hours) come in the next pass; this is where they will live.</div></div>
<div class="panel"><h2>Hours this link is on</h2><div class="muted">Outside these hours visitors go to the fallback. Each destination can have its own hours too (the clock button on its row). Tap a cell to flip it, drag to paint, or start from a preset.</div><div id="rotHours"></div></div>
<div class="panel" style="margin-top:12px"><h2>Clicks by hour, UTC, all time</h2><div class="bars" id="hourBars" style="grid-template-columns:repeat(24,minmax(0,1fr))"></div><div class="axis"><span>00</span><span>06</span><span>12</span><span>18</span><span>23</span></div><div class="muted" id="offNote"></div></div>
</div>
<div id="tab-sources" hidden>
<div class="two">
@@ -112,6 +136,6 @@
</div>
</div>
<script src="/assets/cr-shell.js?v=20261008c"></script>
<script src="/assets/links.js?v=20260929d"></script>
<script src="/assets/links.js?v=20261010a"></script>
</body>
</html>