PageSourceSearch

https://nus-oss.github.io/markbind/js/theme-manager.js

js nus-oss.github.io collected 2026-10-03 09:41:58 UTC 866 bytes, 26 lines download raw bytes

1/**
2 * Loaded as early as possible in <head> to prevent flash of unstyled content (FOUC).
3 * Sets data-bs-theme on <html> before any stylesheets are applied.
4 *
5 * Reads from <html> attributes set by the server:
6 *   - data-dark-mode="true|false"
7 */
8(function () {
9  if (document.documentElement.getAttribute('data-dark-mode') !== 'true') return;
10
11  const STORAGE_KEY = 'markbind-theme';
12  let stored;
13  try { stored = localStorage.getItem(STORAGE_KEY); } catch (e) { /* ignore */ }
14
15  let theme;
16  if (stored === 'dark' || stored === 'light') {
17    theme = stored;
18  } else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
19    theme = 'dark';
20  } else {
21    theme = 'light';
22  }
23  document.documentElement.setAttribute('data-bs-theme', theme);
24  window.__MARKBIND_THEME__ = theme;
25  window.__MARKBIND_DARK_MODE__ = true;
26}());

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.