Express + node:sqlite server, vanilla HTML/JS frontend. Daily puzzle by assigned date, puzzle list, shuffle, one-away hint, shareable emoji results, and a password-protected admin page to create and edit puzzles. Answers are checked server-side and never sent before they are solved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
// Small helpers shared by every page.
|
|
function el(tag, attrs = {}, ...kids) {
|
|
const n = document.createElement(tag);
|
|
for (const [k, v] of Object.entries(attrs)) {
|
|
if (k === 'class') n.className = v;
|
|
else if (k.startsWith('on')) n.addEventListener(k.slice(2), v);
|
|
else if (v !== false && v != null) n.setAttribute(k, v === true ? '' : v);
|
|
}
|
|
n.append(...kids.flat().filter((k) => k != null));
|
|
return n;
|
|
}
|
|
|
|
async function api(url, opts = {}) {
|
|
const res = await fetch(url, {
|
|
...opts,
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: opts.body ? JSON.stringify(opts.body) : undefined,
|
|
});
|
|
const data = await res.json().catch(() => ({}));
|
|
return { ok: res.ok, status: res.status, data };
|
|
}
|
|
|
|
function toast(msg) {
|
|
document.querySelector('.toast')?.remove();
|
|
const t = el('div', { class: 'toast', role: 'status' }, msg);
|
|
document.body.append(t);
|
|
setTimeout(() => t.remove(), 1800);
|
|
}
|
|
|
|
const fmtDate = (d) =>
|
|
d ? new Date(d + 'T00:00:00Z').toLocaleDateString(undefined, { timeZone: 'UTC', year: 'numeric', month: 'long', day: 'numeric' }) : '';
|