pub const SCHEME_SCRIPT: &str = "// The visitor\'s color scheme for these pages: System, Light or Dark,\n// remembered for the whole site. Loaded in <head> so a saved choice\n// applies before the first paint. The control ships hidden and this\n// reveals it, so without JavaScript a page follows the system setting\n// (or the scheme it was generated with) and shows no dead control.\n(function () {\n var KEY = \"asbuilt-docs-scheme\";\n var MODES = [\"system\", \"light\", \"dark\"];\n var root = document.documentElement;\n var fallback = root.getAttribute(\"data-theme-default\") || \"system\";\n var mode = fallback;\n try {\n var saved = window.localStorage.getItem(KEY);\n if (MODES.indexOf(saved) >= 0) mode = saved;\n } catch (e) {}\n function apply(next) {\n if (next === \"light\" || next === \"dark\") root.setAttribute(\"data-theme\", next);\n else root.removeAttribute(\"data-theme\");\n }\n apply(mode);\n document.addEventListener(\"DOMContentLoaded\", function () {\n var select = document.getElementById(\"scheme\");\n if (!select) return;\n select.value = mode;\n select.parentElement.hidden = false;\n select.addEventListener(\"change\", function () {\n mode = MODES.indexOf(select.value) >= 0 ? select.value : fallback;\n apply(mode);\n try {\n window.localStorage.setItem(KEY, mode);\n } catch (e) {}\n });\n });\n})();\n";Expand description
The script behind the scheme control, linked in every page’s head.