Spaces:
Sleeping
Sleeping
File size: 1,109 Bytes
2d53953 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | function darkmode() {
const body = document.body;
const headerText = document.getElementById("header-text");
const h1Elements = document.getElementsByTagName("h1"); // Select all h1 elements
// Check if we're currently in light mode (white or default)
if (body.style.backgroundColor === "white" || body.style.backgroundColor === "") {
// Switch to dark mode
body.style.backgroundColor = "black";
body.style.color = "white";
// Update all h1 elements to white
for (let h1 of h1Elements) {
h1.style.color = "white";
}
// Set header-text color if element exists
if (headerText) {
headerText.style.color = "#B1C8C6";
}
} else {
// Switch to light mode
body.style.backgroundColor = "white";
body.style.color = "black";
// Update all h1 elements to black
for (let h1 of h1Elements) {
h1.style.color = "black";
}
// Reset header-text color if element exists
if (headerText) {
headerText.style.color = "black";
}
}
} |