-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUILogic.js
237 lines (197 loc) · 7.82 KB
/
UILogic.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
let modalDisplayType = "flex";
let modalresults = document.getElementById("GameResults");
let spanresults = document.getElementById("closeresults");
spanresults.addEventListener("click", function () {
modalresults.style.display = "none";
});
let modalhow = document.getElementById("howtotext");
let btnhow = document.getElementById("howto");
let spanhow = document.getElementById("closehowto");
btnhow.addEventListener("click", function () {
modalhow.style.display = modalDisplayType;
});
spanhow.addEventListener("click", function () {
modalhow.style.display = "none";
});
let modalstat = document.getElementById("statstext");
let btnstat = document.getElementById("stats");
let spanstat = document.getElementById("closestat");
btnstat.addEventListener("click", function () {
modalstat.style.display = modalDisplayType;
});
spanstat.addEventListener("click", function () {
modalstat.style.display = "none";
});
let modalset = document.getElementById("settingstext");
let btnset = document.getElementById("settings");
let spanset = document.getElementById("closesettings");
btnset.addEventListener("click", function () {
modalset.style.display = modalDisplayType;
});
spanset.addEventListener("click", function () {
modalset.style.display = "none";
});
function clickOutsideModal(event) {
if (event.target == modalhow) {
modalhow.style.display = "none";
} else if (event.target == modalstat) {
modalstat.style.display = "none";
} else if (event.target == modalset) {
modalset.style.display = "none";
} else if (event.target == modalresults) {
modalresults.style.display = "none";
}
}
window.onclick = function (event) {
clickOutsideModal(event);
};
//Dark Theme
const checkbox = document.getElementById("darkthemeswitch");
function setTheme() {
var body = document.body;
//FLAGGLE Letters
var mht = document.getElementById("MainHeaderText");
var ft1 = document.getElementById("ft1");
var ft2 = document.getElementById("ft2");
var ft3 = document.getElementById("ft3");
var ft4 = document.getElementById("ft4");
var ft5 = document.getElementById("ft5");
var ft6 = document.getElementById("ft6");
//Color Keys
var colorkeys = document.getElementById("colorkeys");
//All Modals
//Settings
var settingsmodalbody = document.getElementById("settingsmodalbody");
var settingsmodalheader = document.getElementById("settingsmodalheader");
var closesettings = document.getElementById("closesettings");
//HowTo
var howtomodalbody = document.getElementById("howtomodalbody");
var howtomodalheader = document.getElementById("howtomodalheader");
var closehowto = document.getElementById("closehowto");
//Stats
var statsmodalbody = document.getElementById("statsmodalbody");
var statsmodalheader = document.getElementById("statsmodalheader");
var closestat = document.getElementById("closestat");
//Daily, Guesses, Random, and Share Buttons
var dailyflaggle = document.getElementById("dailyflaggle");
var randomflaggle = document.getElementById("randomflaggle");
var guesses = document.getElementById("guesses");
var sharebutton = document.getElementById("sharebutton");
var middlediv = document.getElementById("middlediv");
//democolors
var demoorange = document.getElementById("demoorange");
var demoyellow = document.getElementById("demoyellow");
var demogreen = document.getElementById("demogreen");
if (checkbox.checked) {
Cookies.set("darkMode", "true", {
sameSite: "strict",
});
body.classList.add("dark");
mht.classList.add("dark");
ft1.classList.add("dark_flaggletext");
ft2.classList.add("dark_flaggletext");
ft3.classList.add("dark_flaggletext");
ft4.classList.add("dark_flaggletext");
ft5.classList.add("dark_flaggletext");
ft6.classList.add("dark_flaggletext");
colorkeys.classList.add("dark_colorkeys");
settingsmodalbody.classList.add("dark");
settingsmodalheader.classList.add("dark");
closesettings.classList.add("dark");
howtomodalbody.classList.add("dark");
howtomodalheader.classList.add("dark");
closehowto.classList.add("dark");
statsmodalbody.classList.add("dark");
statsmodalheader.classList.add("dark");
closestat.classList.add("dark");
dailyflaggle.classList.add("dark");
randomflaggle.classList.add("dark");
guesses.classList.add("dark");
sharebutton.classList.add("dark");
middlediv.classList.add("dark");
demoorange.classList.add("dark");
demoyellow.classList.add("dark");
demogreen.classList.add("dark");
} else {
Cookies.set("darkMode", "false", {
sameSite: "strict",
});
body.classList.remove("dark");
mht.classList.remove("dark");
ft1.classList.remove("dark_flaggletext");
ft2.classList.remove("dark_flaggletext");
ft3.classList.remove("dark_flaggletext");
ft4.classList.remove("dark_flaggletext");
ft5.classList.remove("dark_flaggletext");
ft6.classList.remove("dark_flaggletext");
colorkeys.classList.remove("dark_colorkeys");
settingsmodalbody.classList.remove("dark");
settingsmodalheader.classList.remove("dark");
closesettings.classList.remove("dark");
howtomodalbody.classList.remove("dark");
howtomodalheader.classList.remove("dark");
closehowto.classList.remove("dark");
statsmodalbody.classList.remove("dark");
statsmodalheader.classList.remove("dark");
closestat.classList.remove("dark");
dailyflaggle.classList.remove("dark");
randomflaggle.classList.remove("dark");
guesses.classList.remove("dark");
sharebutton.classList.remove("dark");
middlediv.classList.remove("dark");
demoorange.classList.remove("dark");
demoyellow.classList.remove("dark");
demogreen.classList.remove("dark");
}
}
document.addEventListener("DOMContentLoaded", function () {
/* dark mode stuff */
let darkModeCookie = Cookies.get("darkMode");
if (darkModeCookie === "true") {
document.getElementById("darkthemeswitch").checked = true;
logger("dark mode");
} else if (darkModeCookie === "false") {
document.getElementById("darkthemeswitch").checked = false;
logger("light mode");
}
setTheme();
checkbox.addEventListener("change", setTheme);
/* slider stuff */
document.getElementById("difficultySlider").min = defaultDifficulty;
document.getElementById("difficultySlider").max = maxDifficulty;
/* display tutorial if not already shown before */
if (!window.sessionStorage.getItem("tutorialShown")) {
document.getElementById("howtotext").style.display =
modalDisplayType;
window.sessionStorage.setItem("tutorialShown", "true");
}
});
function hideLoadingScreen() {
window.scrollTo({
top: 0,
behavior: "smooth",
});
let loading = document.getElementById("loading");
let wavetext = document.getElementsByClassName("wavy")[0];
loading.ontransitionend = function() {
loading.style.visibility = "hidden";
wavetext.classList.add("animate");
}
loading.classList.add("hidden");
}
function showLoadingScreen() {
let loading = document.getElementById("loading");
let wavetext = document.getElementsByClassName("wavy")[0];
wavetext.classList.remove("animate");
loading.style.visibility = "visible";
loading.classList.remove("hidden");
}
window.addEventListener("load", hideLoadingScreen);
/* scroll to top on load */
if (history.scrollRestoration) {
history.scrollRestoration = "manual";
} else {
window.onbeforeunload = function () {
window.scrollTo(0, 0);
};
}