mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Refactor theme handling in login page to prioritize saved preferences from localStorage before falling back to system color scheme
This commit is contained in:
parent
175cc70b70
commit
9c9ce5a55d
1 changed files with 11 additions and 6 deletions
|
|
@ -1,11 +1,16 @@
|
|||
$(document).ready(() => {
|
||||
// If no saved preference, use the system's preferred color scheme
|
||||
const systemPrefersDark = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
).matches;
|
||||
savedTheme = systemPrefersDark ? "dark" : "light";
|
||||
// Check if there's a saved theme preference in localStorage
|
||||
let savedTheme = localStorage.getItem("theme");
|
||||
|
||||
// Apply the preferred theme
|
||||
if (!savedTheme) {
|
||||
// If no saved preference, use the system's preferred color scheme
|
||||
const systemPrefersDark = window.matchMedia(
|
||||
"(prefers-color-scheme: dark)",
|
||||
).matches;
|
||||
savedTheme = systemPrefersDark ? "dark" : "light";
|
||||
}
|
||||
|
||||
// Apply the saved or system-preferred theme
|
||||
applyTheme(savedTheme);
|
||||
|
||||
// Toggle theme on change
|
||||
|
|
|
|||
Loading…
Reference in a new issue