-
Couldn't load subscription status.
- Fork 124
add "auto" state to theme toggle #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,9 @@ function toggleTheme() { | |||||||||
| setTheme("dark"); | ||||||||||
| updateItemToggleTheme(); | ||||||||||
| } else if (localStorage.getItem("theme-storage") === "dark") { | ||||||||||
| setTheme("auto"); | ||||||||||
| updateItemToggleTheme(); | ||||||||||
| } else { | ||||||||||
| setTheme("light"); | ||||||||||
| updateItemToggleTheme(); | ||||||||||
| } | ||||||||||
|
|
@@ -20,38 +23,57 @@ function updateItemToggleTheme() { | |||||||||
|
|
||||||||||
| const darkModeStyle = document.getElementById("darkModeStyle"); | ||||||||||
| if (darkModeStyle) { | ||||||||||
| darkModeStyle.disabled = (mode === "light"); | ||||||||||
| if (mode === "dark" || (mode === "auto" && getSystemPrefersDark())) { | ||||||||||
| darkModeStyle.disabled = false; | ||||||||||
| } else { | ||||||||||
| darkModeStyle.disabled = true; | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| const sunIcon = document.getElementById("sun-icon"); | ||||||||||
| const moonIcon = document.getElementById("moon-icon"); | ||||||||||
| if (sunIcon && moonIcon) { | ||||||||||
| sunIcon.style.display = (mode === "dark") ? "block" : "none"; | ||||||||||
| moonIcon.style.display = (mode === "light") ? "block" : "none"; | ||||||||||
| const autoIcon = document.getElementById("auto-icon"); | ||||||||||
| if (sunIcon && moonIcon && autoIcon) { | ||||||||||
| sunIcon.style.display = (mode === "light") ? "block" : "none"; | ||||||||||
| moonIcon.style.display = (mode === "dark") ? "block" : "none"; | ||||||||||
| autoIcon.style.display = (mode === "auto") ? "block" : "none"; | ||||||||||
|
|
||||||||||
| if (mode === "auto") { | ||||||||||
| autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)"; | ||||||||||
|
||||||||||
| autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)"; | |
| autoIcon.style.filter = getSystemPrefersDark() ? "invert(1)" : "invert(0)"; | |
| } else { | |
| autoIcon.style.filter = "none"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic uses
getSavedTheme()at line 61 but directly callslocalStorage.getItem(\"theme-storage\")here. Consider usinggetSavedTheme()consistently for better maintainability and to avoid potential issues if the saved theme is null/undefined.