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
+13 -12
View File
@@ -1,22 +1,23 @@
<!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">
<meta name="robots" content="noindex, nofollow">
<title>Links · LinkSpin</title>
<!--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&family=JetBrains+Mono:wght@500;700&display=swap">
<link rel="stylesheet" href="/assets/cr.css?v=20261020s">
<link rel="stylesheet" href="/assets/cr.css?v=20261101t">
<style>
.ws{display:grid;grid-template-columns:320px minmax(0,1fr);min-height:calc(100vh - 94px)}
.dbody .tiles{grid-template-columns:repeat(auto-fit,minmax(128px,1fr))}
.list{border-right:1px solid var(--line);display:flex;flex-direction:column;min-height:0;background:rgba(255,255,255,.55)}
.list{border-right:1px solid var(--line);display:flex;flex-direction:column;min-height:0;background:var(--panel-glass)}
.list .hd{display:flex;justify-content:space-between;align-items:center;padding:12px 16px;border-bottom:1px solid var(--line)}
.list .hd h2{font-family:var(--display);font-size:20px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;margin:0}
.list .flt{padding:8px 16px;border-bottom:1px solid var(--line)}
.list .items{overflow:auto}
.item{display:grid;grid-template-columns:minmax(0,1fr) 64px;gap:8px;padding:11px 16px;border-bottom:1px solid var(--line);border-left:3px solid transparent;cursor:pointer}
.item:hover{background:rgba(31,111,235,.05)} .item.on{background:var(--panel);border-left-color:var(--sig)}
.item:hover{background:var(--row-hover)} .item.on{background:var(--panel);border-left-color:var(--sig)}
.item .nm{font-weight:700;display:flex;gap:8px;align-items:center;flex-wrap:wrap} .item .cd{font-family:var(--mono);font-size:11px;color:var(--muted)}
.item .rt{display:grid;justify-items:end;gap:3px} .item .rt .n{font-family:var(--mono)}
.detail{display:flex;flex-direction:column;min-width:0}
@@ -39,9 +40,9 @@
}
.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)}
.hdot.ok{background:var(--ok);box-shadow:0 0 0 2px color-mix(in srgb,var(--ok) 20%,transparent)} .hdot.warn{background:var(--note-line);box-shadow:0 0 0 2px color-mix(in srgb,var(--note-line) 20%,transparent)} .hdot.bad{background:var(--bad);box-shadow:0 0 0 2px color-mix(in srgb,var(--bad) 20%,transparent)}
.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:var(--panel);cursor:pointer;letter-spacing:.02em}
.hchip.set{color:var(--sig-2);border-color:var(--sig-line);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}
@@ -54,7 +55,7 @@
.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}
.note{border:1px solid var(--warn-line);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}
@@ -71,9 +72,9 @@
.vsw .nw{font-family:var(--mono);font-size:9px;letter-spacing:.06em;color:var(--sig-2);margin-left:4px}
.bsr .hd,.bsr .rw{grid-template-columns:minmax(0,2.4fr) 140px 80px 80px 96px 130px}
.bsr .rw.edit{grid-template-columns:1fr;background:var(--panel-2)}
.bthumb{display:block;max-width:100%;max-height:96px;width:auto;height:auto;border:1px solid var(--line);border-radius:4px;background:repeating-conic-gradient(#eef1f5 0 25%,#fff 0 50%) 50%/12px 12px}
.bthumb{display:block;max-width:100%;max-height:96px;width:auto;height:auto;border:1px solid var(--line);border-radius:4px;background:repeating-conic-gradient(var(--panel-2) 0 25%,var(--panel) 0 50%) 50%/12px 12px}
.bprev{display:grid;gap:6px;justify-items:start;overflow:auto;max-width:100%}
.bprev img{display:block;max-width:100%;height:auto;border:1px dashed var(--line-strong);background:repeating-conic-gradient(#eef1f5 0 25%,#fff 0 50%) 50%/12px 12px}
.bprev img{display:block;max-width:100%;height:auto;border:1px dashed var(--line-strong);background:repeating-conic-gradient(var(--panel-2) 0 25%,var(--panel) 0 50%) 50%/12px 12px}
.bframe{border:1px dashed var(--line-strong);display:grid;place-items:center;color:var(--muted);font-family:var(--mono);font-size:11px;max-width:100%;background:var(--panel-2)}
.addg{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px}
.addg .full{grid-column:1/-1}
@@ -85,7 +86,7 @@
.modes{display:grid;gap:8px} .modes label{display:flex;gap:8px;align-items:flex-start;cursor:pointer} .modes input{margin-top:3px}
.bsr .ml{display:none}
.st3 .hd,.st3 .rw{grid-template-columns:minmax(0,2fr) 80px 70px 70px 64px 74px 56px}
.st3 .ml{display:none} .bhl{font-size:11.5px} .bswin{background:var(--ok);color:#fff;border-radius:3px;padding:1px 6px;font-size:10px;font-weight:700;letter-spacing:.06em;margin-left:6px;vertical-align:middle}
.st3 .ml{display:none} .bhl{font-size:11.5px} .bswin{background:var(--ok);color:var(--ok-ink);border-radius:3px;padding:1px 6px;font-size:10px;font-weight:700;letter-spacing:.06em;margin-left:6px;vertical-align:middle}
.bscache{display:block;margin-top:3px;font-size:11px;color:var(--warn)} .bsbreak{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}
@media (max-width:900px){.bsr .ml,.st3 .ml{display:inline;color:var(--muted);font-size:11px}.bsr .rw .r,.st3 .rw .r{text-align:left}.bsr .hd,.st3 .hd{display:none}.bsr .rw{grid-template-columns:1fr 1fr}.st3 .rw{grid-template-columns:1fr 1fr 1fr}.st3 .rw>:first-child{grid-column:1/-1}.addg{grid-template-columns:1fr}.bsbreak{grid-template-columns:1fr}}
@media (max-width:760px){.bsr .rw{grid-template-columns:1fr}.tgt{grid-template-columns:1fr}.vsw{padding:8px 10px 0}.vsw button{padding:6px 10px;font-size:14px}}
@@ -252,7 +253,7 @@
</div>
</div>
</div>
<script src="/assets/cr-shell.js?v=20261025ff"></script>
<script src="/assets/cr-shell.js?v=20261101t"></script>
<script src="/assets/links.js?v=20261021t"></script>
<script src="/assets/banner-spin.js?v=20261020bs3"></script>
</body>