16 lines
617 B
JavaScript
16 lines
617 B
JavaScript
|
function switchTheme(e) {
|
||
|
let actualTheme = document.documentElement.getAttribute('data-theme');
|
||
|
if (actualTheme === null || actualTheme === 'light') {
|
||
|
document.documentElement.setAttribute('data-theme', 'dark');
|
||
|
localStorage.setItem('theme', 'dark');
|
||
|
} else {
|
||
|
document.documentElement.setAttribute('data-theme', 'light');
|
||
|
localStorage.setItem('theme', 'light');
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
const currentTheme = localStorage.getItem('theme') ? localStorage.getItem('theme') : null;
|
||
|
if (currentTheme) {
|
||
|
document.documentElement.setAttribute('data-theme', currentTheme);
|
||
|
}
|