mirror of
https://github.com/13hannes11/hugo-coder-timeline.git
synced 2024-09-04 00:50:58 +02:00
Store theme only when changed from toggle (#579)
Otherwise, it never gets changed according to OS settings. Co-authored-by: Luiz F. A. de Prá <luizdepra@users.noreply.github.com>
This commit is contained in:
@@ -13,7 +13,9 @@ if (localStorage.getItem("colorscheme")) {
|
|||||||
|
|
||||||
if (darkModeToggle) {
|
if (darkModeToggle) {
|
||||||
darkModeToggle.addEventListener('click', () => {
|
darkModeToggle.addEventListener('click', () => {
|
||||||
setTheme(body.classList.contains("colorscheme-dark") ? "light" : "dark");
|
let theme = body.classList.contains("colorscheme-dark") ? "light" : "dark";
|
||||||
|
setTheme(theme);
|
||||||
|
rememberTheme(theme);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,8 +30,11 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
|
|
||||||
function setTheme(theme) {
|
function setTheme(theme) {
|
||||||
body.classList.remove('colorscheme-auto');
|
body.classList.remove('colorscheme-auto');
|
||||||
const inverse = theme === 'dark' ? 'light' : 'dark';
|
let inverse = theme === 'dark' ? 'light' : 'dark';
|
||||||
localStorage.setItem('colorscheme', theme);
|
|
||||||
body.classList.remove('colorscheme-' + inverse);
|
body.classList.remove('colorscheme-' + inverse);
|
||||||
body.classList.add('colorscheme-' + theme);
|
body.classList.add('colorscheme-' + theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function rememberTheme(theme) {
|
||||||
|
localStorage.setItem('colorscheme', theme);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user