forked from b2a3e8/jekyll-theme-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
71 lines (65 loc) · 2.45 KB
/
index.js
File metadata and controls
71 lines (65 loc) · 2.45 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// define items to change colour
const body = document.getElementById("body");
const paragraph = document.getElementsByTagName("p");
const links = document.getElementsByTagName("a");
style = "default"
// check if DOM content is loaded
document.addEventListener('DOMContentLoaded', function() {
const button = document.getElementById("changeStyleBtn");
// Attach event listener to the button
button.addEventListener("click", function() {
if (changeStyleBtn.classList.contains("dark")) {
console.log("default")
changeStyleBtn.classList.remove("dark");
changeStyleBtn.classList.add("default");
// change style to be current style
changeStyle("default");
// set button text to be next style
changeStyleBtn.textContent = "White Theme (!! FLASHBANG WARNING !!)";
}
// loaded toggle loop starts here
else if (changeStyleBtn.classList.contains("default")) {
console.log("white")
changeStyleBtn.classList.remove("default");
changeStyleBtn.classList.add("white");
changeStyle("white");
changeStyleBtn.textContent = "Dark Theme";
}
else {
console.log("dark")
changeStyleBtn.classList.remove("white");
changeStyleBtn.classList.add("dark");
changeStyle("dark");
changeStyleBtn.textContent = "Default Theme";
}
});
});
function changeStyle(style) {
if (style == "dark") {
document.body.style.backgroundColor = "black";
for (let i = 0; i < paragraph.length; i++) {
paragraph[i].style.color = "white";
}
for (let i = 0; i < links.length; i++) {
links[i].style.color = "white";
}
}
else if (style == "white") {
document.body.style.backgroundColor = "white";
for (let i = 0; i < links.length; i++) {
links[i].style.color = "black";
}
for (let i = 0; i < paragraph.length; i++) {
paragraph[i].style.color = "black";
}
}
else if (style == "default") {
document.body.style.backgroundColor = "";
for (let i = 0; i < links.length; i++) {
links[i].style.color = ""; // Change the font color to blue
}
for (let i = 0; i < paragraph.length; i++) {
paragraph[i].style.color = ""; // Change the font color to blue
}
}
};