diff --git a/js/theme.js b/js/theme.js new file mode 100644 index 0000000..4cfbb77 --- /dev/null +++ b/js/theme.js @@ -0,0 +1,22 @@ +function toggleTheme() { + const body = document.body; + const btn = document.getElementById('toggle-theme'); + body.classList.toggle('light-mode'); + + if (body.classList.contains('light-mode')) { + btn.textContent = '🌙'; + localStorage.setItem('theme', 'light'); + } else { + btn.textContent = '☀️'; + localStorage.setItem('theme', 'dark'); + } +} + +(function() { + const theme = localStorage.getItem('theme'); + const btn = document.getElementById('toggle-theme'); + if (theme === 'light') { + document.body.classList.add('light-mode'); + if (btn) btn.textContent = '🌙'; + } +})(); \ No newline at end of file