Theme switch: auto | light | dark, stored in localStorage ls.theme and on the account, applied before first paint on every page

themehead.js is the one source of the tiny inline head script (and of AUTO_DEFAULT, the one constant Marty decides later: 0 = nothing stored keeps the page's current look, light for Control Room and public pages, dark for the sapphire pages; 1 = follow the device). The script sets data-theme on <html> from ls.theme (auto follows prefers-color-scheme and tracks changes live) and exposes window.LSTheme. tools/stamp-theme-head.cjs writes it into every static page before the first stylesheet with data-theme-base on <html>; blog, leaderboard, what's-new, the badge page, the unsubscribe page and the wall 404 read the module directly. The site CSP allows inline scripts by hash only, so themehead.CSP_HASH joins script-src (the script was silently blocked until then).

Account side: accounts.theme (JSON store and MySQL, alterSafe column), in the public account JSON and /api/me; POST /api/my/profile {theme} rides the existing profile save path and never touches the username. cr-shell.js renders a Light / Dark / Auto segmented control in the topbar of every Control Room screen and paints every .theme-seg on the page (the Profile pane gains an Appearance card with the same control); a click applies at once, saves locally and to the account when signed in; at sign-in the account value wins over the local one, and a local choice is pushed up when the account has none yet. view.html stops reading an undefined --bg so its light variant has a light stage. ?v= tags bumped on every changed stylesheet and script (20261101t / ls20261101t).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-11-01 10:44:40 -06:00
parent 7c8f204f5a
commit b84eed3be5
42 changed files with 299 additions and 188 deletions
+6 -5
View File
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en">
<html lang="en" data-theme-base="light">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
@@ -12,15 +12,16 @@
<meta property="og:image" content="{{SITE_URL}}/banners/linkspin-og-1200x630.png">
<meta name="theme-color" content="#0B1424">
<link rel="icon" type="image/png" href="/logo-icon.png">
<!--theme-head--><script>(function(){var A=0,h=document.documentElement,b=h.getAttribute("data-theme-base")||"light",m=window.matchMedia?matchMedia("(prefers-color-scheme: dark)"):{matches:false},v;function g(){try{v=localStorage.getItem("ls.theme")}catch(e){v=null}return v==="light"||v==="dark"||v==="auto"?v:(A?"auto":b)}function ap(){var c=g();h.setAttribute("data-theme",c==="auto"?(m.matches?"dark":"light"):c);h.setAttribute("data-theme-choice",c)}ap();if(m.addEventListener)m.addEventListener("change",ap);else if(m.addListener)m.addListener(ap);window.LSTheme={base:b,get:g,apply:ap,set:function(c,quiet){try{if(c==="light"||c==="dark"||c==="auto")localStorage.setItem("ls.theme",c);else localStorage.removeItem("ls.theme")}catch(e){}ap();if(!quiet)try{dispatchEvent(new CustomEvent("ls-theme",{detail:g()}))}catch(e){}}}})()</script><!--/theme-head-->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Manrope:wght@400;500;700;800&family=JetBrains+Mono:wght@500;700&display=swap">
<link rel="stylesheet" href="/assets/pub.css?v=20261007b">
<link rel="stylesheet" href="/assets/pub.css?v=20261101t">
<style>
.strip .n{font-family:var(--display);font-size:22px;color:var(--chrome-ink);letter-spacing:.04em;line-height:1}
.strip .st{display:flex;align-items:baseline;gap:8px}
.sizes{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:12px}
.sz{padding:14px;display:flex;flex-direction:column;gap:10px;min-height:130px}
.sz .box{height:62px;display:flex;align-items:center;justify-content:center}
.sz .box i{display:block;background:repeating-linear-gradient(135deg,var(--accent-soft) 0 4px,#fff 4px 8px);border:1.5px solid var(--accent-dim);border-radius:2px}
.sz .box i{display:block;background:repeating-linear-gradient(135deg,var(--accent-soft) 0 4px,var(--panel) 4px 8px);border:1.5px solid var(--accent-dim);border-radius:2px}
.sz .lab{display:flex;justify-content:space-between;align-items:center;gap:6px;flex-wrap:wrap}
.sz .lab b{font:700 14px var(--mono)}
.steps{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px;counter-reset:step}
@@ -34,8 +35,8 @@
.rates td.n{font:700 15px var(--mono);white-space:nowrap}
.yesno{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}
.yesno ul{margin:0;padding-left:18px;color:var(--ink-2);display:flex;flex-direction:column;gap:8px;font-size:15px}
.tag.v{border-color:rgba(255,106,26,.45);color:var(--sig-2);background:var(--sig-soft)}
.code{display:block;background:var(--inset);border:1px solid var(--chrome-line);border-radius:6px;color:#8CC8FF;font:500 12px var(--mono);padding:12px 14px;line-height:1.6;overflow-wrap:anywhere}
.tag.v{border-color:var(--sig-line);color:var(--sig-2);background:var(--sig-soft)}
.code{display:block;background:var(--inset);border:1px solid var(--chrome-line);border-radius:6px;color:var(--chrome-hi);font:500 12px var(--mono);padding:12px 14px;line-height:1.6;overflow-wrap:anywhere}
.faq details{border:1px solid var(--line);border-radius:8px;background:var(--panel);padding:0 18px}
.faq summary{cursor:pointer;font-weight:700;padding:14px 0;list-style:none;display:flex;justify-content:space-between;gap:12px}
.faq summary::-webkit-details-marker{display:none}