SPB Git

Repository Public

theme-init.js 1.4 KB 26 lines javascript

1/* Applies the stored theme AND the cached branding before first paint. External + same-origin2   because the CSP forbids inline scripts. Stores nothing sensitive: the theme is "light" | "dark" |3   "system"; the branding ("cr-branding") is the public {agent, productName, agentName} of the last4   /auth/status answer — the app confirms or corrects it as soon as the server answers. */5(function () {6  var root = document.documentElement;7  try {8    var pref = localStorage.getItem('cr.theme') || 'light';9    var dark = pref === 'dark' || (pref === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches);10    root.setAttribute('data-theme', dark ? 'dark' : 'light');11    root.setAttribute('data-theme-pref', pref);12    var meta = document.querySelector('meta[name="theme-color"]');13    if (meta) meta.setAttribute('content', dark ? '#080B10' : '#F7F6F3');14  } catch (e) {15    /* storage unavailable: the CSS default (light) applies */16  }17  try {18    var b = JSON.parse(localStorage.getItem('cr-branding') || 'null');19    var ok = b && (b.agent === 'claude' || b.agent === 'codex') && typeof b.productName === 'string' && b.productName.length > 0 && b.productName.length <= 40;20    root.setAttribute('data-agent', ok ? b.agent : 'claude');21    if (ok && b.agent !== 'claude') document.title = b.productName;22  } catch (e) {23    root.setAttribute('data-agent', 'claude'); /* corrupted cache or no storage: the default product */24  }25})();26
Files main
Menu

Theme