1(function () { 2 "use strict"; 3 4 var STORAGE_KEY = "theme"; 5 var DARK = "dark"; 6 var LIGHT = "light"; 7 8 function getPreferred() { 9 var stored = null; 10 try { stored = localStorage.getItem(STORAGE_KEY); } catch (e) { /* noop */ } 11 if (stored === DARK || stored === LIGHT) return stored; 12 if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) { 13 return DARK; 14 } 15 return LIGHT; 16 } 17 18 function apply(theme) { 19 document.documentElement.setAttribute("data-theme", theme); 20 var btn = document.getElementById("theme-toggle"); 21 if (btn) { 22 btn.setAttribute("aria-label", theme === DARK ? "Switch to light mode" : "Switch to dark mode"); 23 btn.textContent = theme === DARK ? "\u2600\uFE0F" : "\uD83C\uDF19"; 24 } 25 } 26 27 function toggle() { 28 var current = document.documentElement.getAttribute("data-theme") || LIGHT; 29 var next = current === DARK ? LIGHT : DARK; 30 apply(next); 31 try { localStorage.setItem(STORAGE_KEY, next); } catch (e) { /* noop */ } 32 } 33 34 /* Apply on load (the inline script in <head> already set data-theme, 35 but we update the button state here). */ 36 apply(getPreferred()); 37 38 function init() { 39 var btn = document.getElementById("theme-toggle"); 40 if (btn) { 41 btn.addEventListener("click", toggle); 42 /* Re-apply so button label is correct */ 43 apply(getPreferred()); 44 } 45 } 46 47 if (document.readyState === "loading") { 48 document.addEventListener("DOMContentLoaded", init); 49 } else { 50 init(); 51 } 52 53 /* Listen for OS theme changes */ 54 if (window.matchMedia) { 55 window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function (e) { 56 var stored = null; 57 try { stored = localStorage.getItem(STORAGE_KEY); } catch (ex) { /* noop */ } 58 if (!stored) { 59 apply(e.matches ? DARK : LIGHT); 60 } 61 }); 62 } 63})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.