-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathscript.js
More file actions
19 lines (15 loc) · 698 Bytes
/
script.js
File metadata and controls
19 lines (15 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Theme toggle functionality
const toggle = document.getElementById("toggleTheme");
const root = document.documentElement;
const storedTheme = localStorage.getItem("theme");
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
const theme = storedTheme || (prefersDark ? 'dark' : 'light');
root.setAttribute("data-theme", theme);
toggle.addEventListener("click", () => {
const current = root.getAttribute("data-theme");
const newTheme = current === "dark" ? "light" : "dark";
root.setAttribute("data-theme", newTheme);
localStorage.setItem("theme", newTheme);
});
// Dynamic Year
document.getElementById("year").textContent = new Date().getFullYear();