diff --git a/dark-mode.js b/dark-mode.js new file mode 100644 index 00000000..c07dabbd --- /dev/null +++ b/dark-mode.js @@ -0,0 +1,29 @@ +document.addEventListener("DOMContentLoaded", function () { + const themeToggleCheckbox = document.querySelector("#theme-toggle"); + const themeLabel = document.querySelector(".toggle-label"); + + // Function to set the theme + function setTheme(theme) { + if (theme === "dark") { + document.body.classList.add("dark-mode"); + themeLabel.textContent = "Dark Mode"; + themeToggleCheckbox.checked = true; + } else { + document.body.classList.remove("dark-mode"); + themeLabel.textContent = "Light Mode"; + themeToggleCheckbox.checked = false; + } + localStorage.setItem("theme", theme); + } + + // Load the theme from localStorage + const savedTheme = localStorage.getItem("theme") || "light"; + setTheme(savedTheme); + + // Add event listener to toggle checkbox + themeToggleCheckbox.addEventListener("change", () => { + const newTheme = themeToggleCheckbox.checked ? "dark" : "light"; + setTheme(newTheme); + }); + }); + \ No newline at end of file diff --git a/index.html b/index.html index 7779868d..71b0e7b3 100644 --- a/index.html +++ b/index.html @@ -4,312 +4,47 @@