PageSourceSearch

https://www.moscovich.net/scripts/theme-toggle.js

js moscovich.net collected 2026-10-05 19:13:55 UTC 991 bytes, 37 lines download raw bytes

1class ThemeManager {
2    constructor() {
3        this.html = document.documentElement
4        this.init()
5    }
6
7    init() {
8        document.addEventListener("DOMContentLoaded", () => this.updateIcons())
9    }
10
11    toggle() {
12        const isDark = this.html.classList.contains("dark")
13        const newTheme = isDark ? "light" : "dark"
14
15        this.html.classList.toggle("dark", newTheme === "dark")
16        localStorage.setItem("theme", newTheme)
17        this.updateIcons()
18    }
19
20    updateIcons() {
21        const isDark = this.html.classList.contains("dark")
22        const sunIcon = document.getElementById("sun-icon")
23        const moonIcon = document.getElementById("moon-icon")
24
25        if (sunIcon && moonIcon) {
26            sunIcon.classList.toggle("hidden", !isDark)
27            moonIcon.classList.toggle("hidden", isDark)
28        }
29    }
30}
31
32const themeManager = new ThemeManager()
33
34// Global function for theme toggle button
35function toggleTheme() {
36    themeManager.toggle()
37}

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.