Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
432 lines (381 loc) · 14.9 KB
/
Copy pathscript.js
File metadata and controls
432 lines (381 loc) · 14.9 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
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
//element theme colors
const fireColor = "#AC1904";
const fireText = "#E4A006";
const earthColor = "#267903";
const earthText = "#E3FF09";
const waterColor = "#0E7CAB";
const waterText = "#B8EEFF";
const airColor = "#5D088D";
const airText = "#1AF2E5";
//this function returns the color theme for each sign
function getSignColor(sign) {
//fire signs
if (sign == "aries" || sign == "leo" || sign == "sagittarius") {
return { nav: fireColor, text: fireText };
}
//earth signs
if (sign == "taurus" || sign == "virgo" || sign == "capricorn") {
return { nav: earthColor, text: earthText };
}
//water signs
if (sign == "cancer" || sign == "scorpio" || sign == "pisces") {
return { nav: waterColor, text: waterText };
}
//air signs
if (sign == "gemini" || sign == "libra" || sign == "aquarius") {
return { nav: airColor, text: airText };
}
//default
return { nav: "black", text: "white" };
}
//goes through all the sign buttons and colors them
function applySignButtonColors() {
const buttons = document.querySelectorAll("[data-sign]");
for (let i = 0; i < buttons.length; i++) {
const btn = buttons[i];
const sign = btn.getAttribute("data-sign");
const theme = getSignColor(sign);
//using important so theme switcher doesnt overwrite
btn.style.backgroundColor = theme.nav;
btn.style.color = theme.text;
btn.style.border = "1px solid " + theme.text;
}
}
//changes the page theme colors and background
function applyTheme(gif) {
let theme;
//check which gif was picked and set the colors
if (gif === "pictures/themes/fire-theme.gif") {
theme = { nav: fireColor, text: fireText };
} else if (gif === "pictures/themes/earth-theme.gif") {
theme = { nav: earthColor, text: earthText };
} else if (gif === "pictures/themes/water-theme.gif") {
theme = { nav: waterColor, text: waterText };
} else if (gif === "pictures/themes/air-theme.gif") {
theme = { nav: airColor, text: airText };
} else {
theme = { nav: "black", text: "white" };
}
//saves the current theme so the modal can use it
currentTheme = theme;
//sets the background
if (gif) {
document.body.style.backgroundImage = "url('" + gif + "')";
} else {
document.body.style.backgroundImage = "url('pictures/rain.gif')";
}
//changes the nav background color
document.querySelector(".nav-container").style.backgroundColor = theme.nav;
//main headings and nav
const brightColor = document.querySelectorAll(
".sign-name, .p-learn-container, .h1-container, .sign-dates",
);
for (let i = 0; i < brightColor.length; i++) {
brightColor[i].style.color = theme.text;
}
//title and date use the darker theme color, white in default
const titleColor = theme.nav === "black" ? "white" : theme.nav;
const darkColor = document.querySelectorAll(".h1-header, #today-date");
for (let i = 0; i < darkColor.length; i++) {
darkColor[i].style.color = titleColor;
}
//updates button colors
const allButtons = document.querySelectorAll("button");
for (let i = 0; i < allButtons.length; i++) {
const btn = allButtons[i];
if (btn.classList.contains("sign-card") || btn.closest(".zodiac-nav")) {
continue;
}
btn.style.backgroundColor = theme.nav;
btn.style.color = theme.text;
btn.style.border = "1px solid " + theme.text;
}
applySignButtonColors();
//styles the theme select dropdown menu
const bgSelect = document.getElementById("bg-select");
bgSelect.style.backgroundColor = theme.nav;
bgSelect.style.color = theme.text;
bgSelect.style.border = "2px solid " + theme.text;
//styles the footer
const footer = document.querySelector(".footer");
if (footer) {
footer.style.backgroundColor = theme.nav;
footer.style.color = theme.text;
}
const footerLinks = document.querySelectorAll(".footer-links a");
for (let i = 0; i < footerLinks.length; i++) {
footerLinks[i].style.color = theme.text;
}
const footerCopy = document.querySelector(".footer-copy");
if (footerCopy) {
footerCopy.style.color = theme.text;
}
//styles the icon area in the nav
document.querySelector(".nav-color").style.backgroundColor = theme.nav;
const icon = document.querySelector(".nav-color img");
if (icon) {
icon.style.filter = "drop-shadow(0 0 6px " + theme.text + ")";
}
}
//show today's date on the page
const todayDate = new Date();
document.getElementById("today-date").textContent =
todayDate.toLocaleDateString("en-US", {
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
});
//tracks whatever theme is currently active
let currentTheme = { nav: "black", text: "white" };
//resets to default after 5 minutes
const THEME_TIMEOUT = 5 * 60 * 1000;
let themeTimer = null;
function resetToDefault() {
applyTheme("");
document.getElementById("bg-select").value = "";
}
//always start with default on page load
applyTheme("");
//listens for theme changes in the dropdown
document.getElementById("bg-select").addEventListener("change", (e) => {
applyTheme(e.target.value);
clearTimeout(themeTimer);
if (e.target.value) {
//resets to default after 5 minutes
themeTimer = setTimeout(resetToDefault, THEME_TIMEOUT);
}
});
//close button for the horoscope modal
document.getElementById("modal-close").addEventListener("click", () => {
document.getElementById("modal").classList.remove("active");
});
//clicking the backdrop closes modal
document.getElementById("modal").addEventListener("click", (e) => {
if (e.target === e.currentTarget) {
e.currentTarget.classList.remove("active");
}
});
//loads horoscope from today or yesterdays jsnon
function loadHoroscope(sign, file) {
const video = document.getElementById("loading-video");
const result = document.getElementById("horoscope-result");
const yesterdayBtn = document.getElementById("yesterday-btn");
const modalTheme =
currentTheme.nav === "black" ? getSignColor(sign) : currentTheme;
const isYesterday = file === "horoscope_yesterday.json";
yesterdayBtn.style.display = "none";
video.style.display = isYesterday ? "none" : "block";
result.style.display = isYesterday ? "block" : "none";
fetch(file)
.then((response) => response.json())
.then((data) => {
const horoscope = data[sign].summary;
const dateLabel = data[sign].date;
result.innerHTML =
'<h2 id="modal-heading" style="color:' +
modalTheme.text +
'">' +
sign.toUpperCase() +
" Horoscope</h2>" +
'<p class="modal-date" style="color:' +
modalTheme.nav +
'; font-size:20px; font-weight: bold;">' +
dateLabel +
"</p>" +
'<p style="color:' +
modalTheme.text +
'">' +
horoscope +
"</p>";
const show = () => {
video.style.display = "none";
result.style.display = "block";
if (!isYesterday) {
yesterdayBtn.style.display = "block";
yesterdayBtn.style.color = modalTheme.text;
yesterdayBtn.style.borderColor = modalTheme.text;
}
};
isYesterday ? show() : setTimeout(show, 5000);
})
.catch(() => {
document.getElementById("modal").classList.remove("active");
alert("Could not load horoscope data. Please try again.");
});
}
//adds event listener to each horoscope button
const horoBtn = document.querySelectorAll(".sign-card");
for (let i = 0; i < horoBtn.length; i++) {
horoBtn[i].addEventListener("click", () => {
const sign = horoBtn[i].getAttribute("data-sign");
const modalTheme =
currentTheme.nav === "black" ? getSignColor(sign) : currentTheme;
document.querySelector(".modal-content").style.border =
"1px solid " + modalTheme.text;
document.getElementById("modal-close").style.color = modalTheme.text;
document.getElementById("loading-video").src =
"pictures/season/" + sign + "-season.webp";
document.getElementById("modal").classList.add("active");
document.getElementById("yesterday-btn").onclick = () => {
loadHoroscope(sign, "horoscope_yesterday.json");
};
loadHoroscope(sign, "horoscope.json");
});
}
//opens the sign info overlay panel
function openSign(sign) {
//shows the overlay with the loading gif right away
const overlay = document.getElementById("sign-info");
const loadingGif = document.getElementById("sign-info-loading");
const signContent = document.querySelector(".sign-info-content");
overlay.style.display = "block";
loadingGif.style.display = "block";
signContent.style.display = "none";
fetch("zodiac.json")
.then((res) => res.json())
.then((data) => {
const info = data[sign];
//fills in all the text fields
document.getElementById("name").textContent = info.name;
document.getElementById("dates").textContent = info.dates;
document.getElementById("element").textContent = info.element;
document.getElementById("symbol").textContent = info.symbol;
document.getElementById("modality").textContent = info.modality;
document.getElementById("polarity").textContent = info.polarity;
document.getElementById("ruling_planet").textContent = info.ruling_planet;
document.getElementById("ruling_planet_traditional").textContent =
info.ruling_planet_traditional || "—";
document.getElementById("house").textContent = info.house;
document.getElementById("season").textContent = info.season || "—";
document.getElementById("tarot_card").textContent =
info.tarot_card || "—";
document.getElementById("body_part").textContent = info.body_part || "—";
//builds traits list
let traitsList = "";
for (let i = 0; i < info.traits.length; i++) {
traitsList = traitsList + "<li>" + info.traits[i] + "</li>";
}
document.getElementById("traits").innerHTML = traitsList;
//builds strengths list
let strengthsList = "";
for (let i = 0; i < info.strengths.length; i++) {
strengthsList = strengthsList + "<li>" + info.strengths[i] + "</li>";
}
document.getElementById("strengths").innerHTML = strengthsList;
//builds weaknesses list
let weaknessesList = "";
for (let i = 0; i < info.weaknesses.length; i++) {
weaknessesList = weaknessesList + "<li>" + info.weaknesses[i] + "</li>";
}
document.getElementById("weaknesses").innerHTML = weaknessesList;
//all other values for sign
document.getElementById("keywords").textContent =
info.keywords.join(", ");
document.getElementById("lucky_colors").textContent =
info.lucky_colors.join(", ");
document.getElementById("lucky_numbers").textContent =
info.lucky_numbers.join(", ");
document.getElementById("lucky_day").textContent = info.lucky_day || "—";
document.getElementById("lucky_gemstone").textContent =
info.lucky_gemstone || "—";
document.getElementById("compatibility").textContent =
info.compatibility.join(", ");
document.getElementById("least_compatible").textContent =
info.least_compatible ? info.least_compatible.join(", ") : "—";
document.getElementById("love_style").textContent =
info.love_style || "—";
document.getElementById("friendship_style").textContent =
info.friendship_style || "—";
document.getElementById("career_strengths").textContent =
info.career_strengths || "—";
document.getElementById("shadow_side").textContent =
info.shadow_side || "—";
document.getElementById("spiritual_lesson").textContent =
info.spiritual_lesson || "—";
document.getElementById("famous_examples").textContent =
info.famous_examples ? info.famous_examples.join(", ") : "—";
document.getElementById("description").textContent = info.description;
//if no theme is picked just use the signs element color
const activeTheme =
currentTheme.nav === "black" ? getSignColor(sign) : currentTheme;
//sign name gets the bright color, date gets darker one
document.getElementById("name").style.color = activeTheme.text;
document.getElementById("dates").style.color = activeTheme.nav;
//color all the h2 headings
const headings = document.querySelectorAll("#sign-info h2");
for (let i = 0; i < headings.length; i++) {
headings[i].style.color = activeTheme.nav;
}
//the bold label words like
const boldTxt = document.querySelectorAll(".about-sign b");
for (let i = 0; i < boldTxt.length; i++) {
boldTxt[i].style.color = activeTheme.nav;
}
//actual values next to those labels
const spanTxt = document.querySelectorAll(".about-sign span");
for (let i = 0; i < spanTxt.length; i++) {
spanTxt[i].style.color = activeTheme.text;
}
//lists get the brighter color
document.getElementById("traits").style.color = activeTheme.text;
document.getElementById("strengths").style.color = activeTheme.text;
document.getElementById("weaknesses").style.color = activeTheme.text;
//all the info paragraphs at the bottom
const signInfoFields = [
"keywords",
"lucky_colors",
"lucky_numbers",
"lucky_day",
"lucky_gemstone",
"compatibility",
"least_compatible",
"love_style",
"friendship_style",
"career_strengths",
"shadow_side",
"spiritual_lesson",
"famous_examples",
"description",
];
for (let i = 0; i < signInfoFields.length; i++) {
document.getElementById(signInfoFields[i]).style.color =
activeTheme.text;
}
// determine background gif based on element
let bgGif = "pictures/rain.gif";
if (info.element === "Fire") {
bgGif = "pictures/themes/fire-theme.gif";
} else if (info.element === "Earth") {
bgGif = "pictures/themes/earth-theme.gif";
} else if (info.element === "Water") {
bgGif = "pictures/themes/water-theme.gif";
} else if (info.element === "Air") {
bgGif = "pictures/themes/air-theme.gif";
}
//dark gradient top of gif so the text is readable
overlay.style.backgroundImage =
"linear-gradient(rgba(0,0,0,0.82), rgba(0,0,0,0.82)), url('" +
bgGif +
"')";
//wait 3 seconds then swap the loading gif for the horoscope
setTimeout(() => {
loadingGif.style.display = "none";
signContent.style.display = "block";
}, 3000);
})
.catch(() => {
document.getElementById("sign-info").style.display = "none";
alert("Could not load sign data. Please try again.");
});
}
//close the sign info
document.getElementById("sign-info-close").addEventListener("click", () => {
document.getElementById("sign-info").style.display = "none";
});
//clicking the backdrop also closes the sign info overlay
document.getElementById("sign-info").addEventListener("click", (e) => {
if (e.target === e.currentTarget) {
e.currentTarget.style.display = "none";
}
});