Skip to content
Snippets Groups Projects
Commit a9554c54 authored by Miniontoby's avatar Miniontoby :writing_hand_tone1:
Browse files

Added auto dark theme chooser based on system settings

parent 214dfeef
No related branches found
No related tags found
No related merge requests found
...@@ -152,7 +152,9 @@ function initButtons() { ...@@ -152,7 +152,9 @@ function initButtons() {
} }
function initDarkmode() { function initDarkmode() {
const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]'), currentTheme = localStorage.getItem('theme'); const toggleSwitch = document.querySelector('.theme-switch input[type="checkbox"]')
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
const currentTheme = localStorage.getItem('theme') || ((prefersDarkScheme.matches) ? 'dark' : 'light');
if (currentTheme) { if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme); document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark') toggleSwitch.checked = true; if (currentTheme === 'dark') toggleSwitch.checked = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment