27 lines
No EOL
772 B
JavaScript
27 lines
No EOL
772 B
JavaScript
document.querySelector('nav > button')?.addEventListener('click', (e) => {
|
|
document.querySelector('nav').classList.toggle('visible');
|
|
})
|
|
|
|
function applyTheme(theme){
|
|
const html = document.querySelector('html')
|
|
document.cookie = `theme=${theme}; path=/; expires=; SameSite=Strict; Secure`
|
|
html.classList.remove('dark', 'light')
|
|
html.classList.add(theme)
|
|
}
|
|
|
|
document.querySelectorAll('.toggleTheme')?.forEach(
|
|
element => element.addEventListener('click', (e) => {
|
|
const newTheme = element.dataset.theme;
|
|
applyTheme(newTheme);
|
|
}
|
|
)
|
|
);
|
|
|
|
const themeFromCookie = document.cookie
|
|
.split("; ")
|
|
.find((row) => row.startsWith("theme="))
|
|
?.split("=")[1];
|
|
|
|
if (themeFromCookie) {
|
|
applyTheme(themeFromCookie)
|
|
} |