-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththemes.js
147 lines (124 loc) · 4.24 KB
/
themes.js
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
window.addEventListener("load", () => {
console.log("themesEnabled");
//Add EventListeners for box
document
.querySelector("#themes_button")
.addEventListener("click", openThemes);
document
.querySelector("#home_button_themes")
.addEventListener("click", closeThemes);
//Add EventListeners for themes
document
.querySelector("#theme_classic")
.addEventListener("click", classicTheme);
document
.querySelector("#theme_pineapple")
.addEventListener("click", pineappleTheme);
document
.querySelector("#theme_azzurri")
.addEventListener("click", azzurriTheme);
//Use locally stored theme
let currentTheme = localStorage.getItem("currentTheme");
if (currentTheme == "azzurriTheme") {
azzurriTheme();
} else if (currentTheme == "pineappleTheme") {
pineappleTheme();
} else {
classicTheme();
}
document.querySelectorAll(".theme").forEach((theme) => {
theme.addEventListener("click", reverseThemes);
});
});
function reverseThemes() {
if (currentTheme != "pineappleTheme") {
document.querySelector("#tomato_sprite").src =
"themes/classicTheme/assets/svg/characters/Tomato.svg";
document.querySelector("#shroom_sprite").src =
"themes/classicTheme/assets/svg/characters/Mushroom.svg";
document.querySelector("#olives_sprite").src =
"themes/classicTheme/assets/svg/characters/Olives.svg";
document.querySelector("#onion_sprite").src =
"themes/classicTheme/assets/svg/characters/Onion.svg";
}
}
function openThemes() {
console.log("openThemes");
//Display themes
document.querySelector("#themes").classList.remove("hidden");
document.querySelector("#shadow").classList.remove("hidden");
document.querySelector("#shadow").style.cursor = "pointer";
document.querySelector("#shadow").addEventListener("click", closeThemes);
}
function closeThemes() {
console.log("closeThemes");
//Undisplay themes
document.querySelector("#themes").classList.add("hidden");
document.querySelector("#shadow").classList.add("hidden");
document.querySelector("#shadow").style.cursor = "auto";
document.querySelector("#shadow").removeEventListener("click", closeThemes);
}
function classicTheme() {
previousTheme = currentTheme;
currentTheme = "classicTheme";
localStorage.setItem("currentTheme", "classicTheme");
//Show selection
document.querySelectorAll(".selector").forEach((selector) => {
selector.classList.remove("selected");
});
document
.querySelector("#theme_classic")
.lastElementChild.lastElementChild.classList.add("selected");
//Change img sources
document.querySelectorAll("img").forEach((image) => {
image.src = image.src.replace(previousTheme, currentTheme);
});
document
.querySelectorAll('div[style*="background-image:"]')
.forEach((image) => {
image.style.backgroundImage = image.style.backgroundImage.replace(
previousTheme,
currentTheme
);
});
}
function pineappleTheme() {
previousTheme = currentTheme;
currentTheme = "pineappleTheme";
localStorage.setItem("currentTheme", "pineappleTheme");
//Show selection
document.querySelectorAll(".selector").forEach((selector) => {
selector.classList.remove("selected");
});
document
.querySelector("#theme_pineapple")
.lastElementChild.lastElementChild.classList.add("selected");
//Change img sources
document.querySelectorAll(".container img").forEach((image) => {
image.src = "themes/classicTheme/assets/svg/characters/Pineapple.svg";
});
}
function azzurriTheme() {
previousTheme = currentTheme;
currentTheme = "azzurriTheme";
localStorage.setItem("currentTheme", "azzurriTheme");
//Show selection
document.querySelectorAll(".selector").forEach((selector) => {
selector.classList.remove("selected");
});
document
.querySelector("#theme_azzurri")
.lastElementChild.lastElementChild.classList.add("selected");
//Change img sources
document.querySelectorAll("img").forEach((image) => {
image.src = image.src.replace(previousTheme, currentTheme);
});
document
.querySelectorAll('div[style*="background-image:"]')
.forEach((image) => {
image.style.backgroundImage = image.style.backgroundImage.replace(
previousTheme,
currentTheme
);
});
}