diff --git a/css/style.css b/css/style.css index 0999795..3ec2374 100644 --- a/css/style.css +++ b/css/style.css @@ -37,7 +37,6 @@ html { font-size: 18px; font-family: var(--font-family); text-wrap: balance; - background-color: pink; } body { diff --git a/js/script.js b/js/script.js index f2b3b54..ea5a026 100644 --- a/js/script.js +++ b/js/script.js @@ -1 +1,15 @@ -console.log("Hola mundo!"); \ No newline at end of file +const themeButton = document.getElementById('theme_button'); +const darkTheme = 'dark-theme'; +const selectedTheme = localStorage.getItem('selected-theme'); +const userHasDarkTheme = window.matchMedia('(prefers-color-scheme: dark)').matches; +const getCurrentTheme = () => document.body.classList.contains(darkTheme) ? 'dark' : 'light'; +if (selectedTheme) { + document.body.classList[selectedTheme === 'dark' ? 'add' : 'remove'](darkTheme); +} else { + if (userHasDarkTheme) document.body.classList.add(darkTheme); +} + +themeButton.addEventListener('click', () => { + document.body.classList.toggle(darkTheme); + localStorage.setItem('selected-theme', getCurrentTheme()); +}); \ No newline at end of file