chore: added CV and theme-toggle-system

This commit is contained in:
Ward Truyen
2024-08-09 15:47:56 +02:00
parent a017d7283f
commit b39c4102ed
4 changed files with 82 additions and 25 deletions

34
src/js/theme.js Normal file
View File

@@ -0,0 +1,34 @@
function toggleTheme() {
const theme = "theme-dark";//localStorage.getItem('theme');
const root = document.querySelector(":root");
root.classList.toggle(theme);
}
function setTheme(themeName) {
console.log("setting them: " + themeName);
const root = document.querySelector(":root");
root.classList.add(themeName);
localStorage.setItem('theme', themeName);
}
function detectTheme() {
const theme = localStorage.getItem('theme');
if (theme === 'theme-dark' || theme === 'theme-light') {
setTheme(theme);
return;
}
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
setTheme('theme-dark');
return;
}
// if (window.matchMedia('(prefers-color-scheme: light)').matches) {
// setTheme('theme-light');
// return;
// }
// setTheme('theme-light');
}
detectTheme();