Skip to content

Commit

Permalink
Add javascript dark toggle mode
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrodmillman committed Oct 24, 2023
1 parent 164a940 commit 1ff4d54
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions assets/js/dark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", ({ matches }) => {
if (matches) {
targetTheme = "dark";
} else {
targetTheme = "light";
}
document.documentElement.setAttribute("data-theme", targetTheme);
localStorage.setItem("theme", targetTheme);
});

0 comments on commit 1ff4d54

Please sign in to comment.