Skip to content

Build your personal knowledge base with Trilium Notes

1.1 KB
Raw Blame
<script>
    // Applies the theme before the first paint, to avoid color flashes, and marks the page as
    // running scripts, which hides what an app view replaces until it mounts. The function keeps
    // its names out of the global scope, which `~shareHtml` snippets share.
    (function () {
        function read(key) {
            try {
                return localStorage.getItem(key);
            } catch {
                return null;
            }
        }

        const root = document.documentElement;
        const prefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
        const stored = read("theme");
        const preference = stored === "light" || stored === "dark" ? stored : "system";
        const theme = preference === "system" ? (prefersDark ? "dark" : "light") : preference;
        root.classList.add(`theme-${theme}`, `theme-preference-${preference}`, "has-scripts");

        window.glob = {
            isShare: true,
            isStatic: <%= !!isStatic %>,
            theme
        };
    })();
</script>