Skip to content

Commit

Permalink
fix(darkmode): check for null (#1531)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackthorne authored Dec 3, 2024
1 parent 285c0e9 commit 5a5ef67
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions quartz/components/scripts/darkmode.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ document.addEventListener("nav", () => {

// Darkmode toggle
const themeButton = document.querySelector("#darkmode") as HTMLButtonElement
themeButton.addEventListener("click", switchTheme)
window.addCleanup(() => themeButton.removeEventListener("click", switchTheme))

if (themeButton) {
themeButton.addEventListener("click", switchTheme)
window.addCleanup(() => themeButton.removeEventListener("click", switchTheme))
}
// Listen for changes in prefers-color-scheme
const colorSchemeMediaQuery = window.matchMedia("(prefers-color-scheme: dark)")
colorSchemeMediaQuery.addEventListener("change", themeChange)
Expand Down

0 comments on commit 5a5ef67

Please sign in to comment.