-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
438 lines (427 loc) · 12.4 KB
/
app.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
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
433
434
435
436
437
438
var showList = document.getElementById("showsList");
const url =
"https://script.google.com/macros/s/AKfycbyiztfyHGcqr8dPB4G-_ruG8IUb2L0d6NJOSuPV5pHEx9oR_KDMwJAHeBsultPxsl48lA/exec"; //deployment url
getData();
var shows4real = [];
var co4real = [];
var franchises = [];
var newShow = {};
var newCO = {};
var newFran = {};
var onlyTheName = [];
function getData() {
fetch(url)
.then((res) => {
return res.json();
})
.then((json) => {
json.data.shows.forEach((ele) => {
newShow = {
title: ele.showname,
star: ele.infiniteearthscanon,
id: ele.showid,
network: ele.network,
summary: ele.summary,
year: ele.year,
franchise: ele.franchiseid,
tmdbID: ele.tmdbid,
imgSrc: ""
};
console.log(newShow.tmdbID);
if (newShow.tmdbID !== "") {
if (newShow.id.charAt(0) === "S"){
newShow = detailsFromTMDBtv(newShow);
}
if (newShow.id.charAt(0) === "M"){
newShow = detailsFromTMDBmovie(newShow);
}
}
shows4real.push(newShow);
if (newShow.id.charAt(0) === "S"||newShow.id.charAt(0) === "M") {
onlyTheName.push(newShow.title);
onlyTheName.sort();
}
var showNameAsOption = document.createElement("option");
//console.log(onlyTheName[onlyTheName.length - 1]);
if (newShow.id.charAt(0) === "S"||newShow.id.charAt(0) === "M") {
showNameAsOption.value = newShow.title;
}
showList.append(showNameAsOption);
});
json.data.crossovers.forEach((ele) => {
newCO = {
show1ID: ele.show1id,
show2ID: ele.show2id,
cross: ele.crossoverdescription,
type: typeName2Num(ele.crossovertype)
};
co4real.push(newCO);
});
json.data.franchises.forEach((ele) => {
newFran = { id: ele.franchiseid, name: ele.name };
franchises.push(newFran);
});
});
}
function search1show(showName) {
var show = document.getElementById("show");
removeAllChildNodes(show);
if (legitShowName(showName) && showName.length > 0) {
viewCrossovers(createShowsCOList(showName));
}
//console.log(franchises);
//print4realz();
}
function search2shows() {
var show = document.getElementById("show");
removeAllChildNodes(show);
var showName1 = document.getElementById("showName1").value;
var showName2 = document.getElementById("showName2").value;
if (
legitShowName(showName1) &&
showName1.length > 0 &&
legitShowName(showName2) &&
showName2.length > 0
) {
if (showName1 === showName2) {
viewCrossovers(createShowsCOList(showName1));
} else {
viewCrossovers(create2showsCOList(showName1, showName2));
}
}
}
document.getElementById("searchShow").onclick = function () {
search1show(document.getElementById("showName1").value);
};
function getShowIDfromName(showName) {
return findShowfromName(showName).id;
}
function legitShowName(showName) {
var i;
for (i = 0; i < onlyTheName.length; i++) {
if (onlyTheName[i] === showName) {
return true;
}
}
return false;
}
function createShowsCOList(showName) {
var showID = getShowIDfromName(showName);
var COList = [];
co4real.map((co) => {
if (co.show1ID === showID || co.show2ID === showID) {
COList.push(co);
}
return co.cross;
});
return COList;
}
function create2showsCOList(showName1, showName2) {
var show1ID = getShowIDfromName(showName1);
var show2ID = getShowIDfromName(showName2);
var COList = [];
co4real.map((co) => {
if (
(co.show1ID === show1ID && co.show2ID === show2ID) ||
(co.show2ID === show1ID && co.show1ID === show2ID)
) {
COList.push(co);
}
return "";
});
return COList;
}
function isCOListfull(crossoverList) {
if (crossoverList.length > 0) {
return true;
}
return false;
}
function removeAllChildNodes(parent) {
while (parent.firstChild) {
parent.removeChild(parent.firstChild);
}
}
function pickAnArrow(COType) {
if (COType === 2) {
return "⟷";
}
return "⟶";
}
document.getElementById("legend").onclick = function () {
document.getElementById("myModal2").style.display = "block";
};
function viewCrossovers(crossoverList) {
var crossovers = document.getElementById("crossovers");
removeAllChildNodes(crossovers);
if (isCOListfull(crossoverList)) {
crossoverList.map((co) => {
var crossover = document.createElement("div");
crossover.style.borderColor = type2color(co.type);
crossover.classList.add("crossover");
crossovers.append(crossover);
var show1 = document.createElement("h2");
show1.innerHTML = findShowfromID(co.show1ID).title;
show1.onclick = function () {
search1show(co.show1);
viewShow(findShowfromID(co.show1ID));
};
crossover.append(show1);
var arrow = document.createElement("h1");
arrow.innerHTML = pickAnArrow(co.type);
arrow.style.color = type2color(co.type);
crossover.append(arrow);
var show2 = document.createElement("h2");
show2.innerHTML = findShowfromID(co.show2ID).title;
show2.onclick = function () {
search1show(co.show2);
viewShow(findShowfromID(co.show2ID));
};
crossover.append(show2);
var details = document.createElement("p");
details.innerHTML = co.cross;
crossover.append(details);
return co.show1;
});
} else {
var message = document.createElement("div");
message.innerHTML = `<h2> ${"sadly there are no crossovers :/"} </h2>`;
crossovers.append(message);
}
}
function findShowfromName(name) {
var showDetails = {};
for (var i in shows4real) {
if (shows4real[i].title === name) {
showDetails = shows4real[i];
}
}
return showDetails;
}
function findShowfromID(id) {
var showDetails = {};
for (var i in shows4real) {
if (shows4real[i].id === id) {
showDetails = shows4real[i];
}
}
return showDetails;
}
var prevSearch = document.getElementById("prevSearch");
var nextSearch = document.getElementById("nextSearch");
var search1 = true;
prevSearch.onclick = function () {
search1 = search1 ? false : true;
changeSearch();
};
nextSearch.onclick = function () {
search1 = search1 ? false : true;
changeSearch();
};
function changeSearch() {
var otherSearchInput = document.getElementById("showName2");
if (search1) {
document.getElementById("info").innerHTML =
"search a show to see its' crossovers";
otherSearchInput.style.display = "none";
document.getElementById("searchShow").onclick = function () {
search1show(document.getElementById("showName1").value);
};
} else {
document.getElementById("info").innerHTML =
"search 2 shows to see if they cross";
otherSearchInput.style.display = "inline-block";
document.getElementById("searchShow").onclick = function () {
search2shows();
};
}
}
function randomShowName() {
var randNum = Math.floor(Math.random() * onlyTheName.length);
return onlyTheName[randNum];
}
document.getElementById("random").onclick = function () {
var randShow = randomShowName();
search1show(randShow);
viewShow(findShowfromName(randShow));
};
function detailsFromTMDBtv(showDetails) {
var updatedShowDetails = showDetails;
var tmdbID = showDetails.tmdbID;
var tmdbURL =
"https://api.themoviedb.org/3/tv/" +
tmdbID +
"?api_key=e9d2e8f44b5d1e54fa22022b4a771f6c&language=en-US";
fetch(tmdbURL)
.then((res) => res.json())
.then((data) => {
console.log(data);
//updatedShowDetails.title = data.name;
updatedShowDetails.network = data.networks[0].name;
updatedShowDetails.year = data.first_air_date.slice(0, 4);
updatedShowDetails.summary = data.overview;
updatedShowDetails.imgSrc =
"https://image.tmdb.org/t/p/w300" + data.poster_path;
});
return updatedShowDetails;
}
function detailsFromTMDBmovie(showDetails) {
var updatedShowDetails = showDetails;
var tmdbID = showDetails.tmdbID;
var tmdbURL =
"https://api.themoviedb.org/3/movie/" +
tmdbID +
"?api_key=e9d2e8f44b5d1e54fa22022b4a771f6c&language=en-US";
fetch(tmdbURL)
.then((res) => res.json())
.then((data) => {
console.log(data);
//updatedShowDetails.title = data.name;
updatedShowDetails.network = data.production_companies[0].name;
updatedShowDetails.year = data.release_date.slice(0, 4);
updatedShowDetails.summary = data.overview;
updatedShowDetails.imgSrc =
"https://image.tmdb.org/t/p/w300" + data.poster_path;
});
return updatedShowDetails;
}
function viewShow(showDetails) {
var show = document.getElementById("show");
removeAllChildNodes(show);
if (showDetails.imgSrc !== "") {
var poster = document.createElement("img");
poster.src = showDetails.imgSrc;
poster.classList = "poster";
show.append(poster);
}
if (showDetails.star === "Yes") {
var star = document.createElement("img");
//star.src = "https://i.imgur.com/cfvVpNu.png";
star.src = "https://i.ibb.co/JkVhX2q/star.png";
star.classList = "star";
show.append(star);
}
var title = document.createElement("h1");
title.innerHTML = showDetails.title;
title.onclick = function () {
search1show(showDetails.title);
viewShow(findShowfromName(showDetails.title));
};
show.append(title);
var year = document.createElement("h2");
year.innerHTML = showDetails.year;
show.append(year);
var network = document.createElement("h2");
network.innerHTML = showDetails.network;
show.append(network);
var summary = document.createElement("p");
summary.innerHTML = showDetails.summary;
summary.classList = "summary";
show.append(summary);
if (showDetails.franchise !== "") {
var franchise = document.createElement("div");
show.append(franchise);
var franchiseName = document.createElement("h2");
franchiseName.innerHTML =
"part of the " +
franchiseNamefromID(showDetails.franchise) +
" franchise";
franchise.append(franchiseName);
var franchiseShow = document.createElement("ul");
franchise.append(franchiseShow);
if (findFranchiseShows(showDetails.franchise, showDetails).length > 0) {
franchiseName.innerHTML += " with:";
findFranchiseShows(showDetails.franchise, showDetails).map(
(showInFranchise) => {
var otherShowName = document.createElement("li");
otherShowName.innerHTML = showInFranchise;
otherShowName.onclick = function () {
search1show(showInFranchise);
viewShow(findShowfromName(showInFranchise));
};
franchise.append(otherShowName);
return showInFranchise;
}
);
}
}
document.getElementById("myModal").style.display = "block";
}
function franchiseNamefromID(id) {
for (var f in franchises) {
if (franchises[f].id === id) {
return franchises[f].name;
}
}
return id;
}
function findFranchiseShows(franchise, showClicked) {
var showsInFranchise = [];
for (var i in shows4real) {
if (
shows4real[i].franchise === franchise &&
showClicked.title !== shows4real[i].title
) {
showsInFranchise.push(shows4real[i].title);
}
}
return showsInFranchise;
}
var span = document.getElementById("close");
var modal = document.getElementById("myModal");
span.onclick = function () {
modal.style.display = "none";
};
window.onclick = function (event) {
if (event.target === modal || event.target === modal2) {
modal.style.display = "none";
modal2.style.display = "none";
}
};
var span2 = document.getElementById("close2");
var modal2 = document.getElementById("myModal2");
span2.onclick = function () {
modal2.style.display = "none";
};
function typeName2Num(typeName) {
if (typeName === "ספינאוף") {
return 1;
}
if (typeName === "חפץ או איזכור") {
return 4;
}
if (typeName === "הופעה של דמות") {
return 3;
}
if (typeName === "קרוסאובר רשמי") {
return 2;
}
if (typeName === "alt' cameo") {
return 6;
}
if (typeName === "show within a show") {
return 5;
}
return 7;
}
function type2color(typeNum) {
if (typeNum === 1) {
return "yellow";
}
if (typeNum === 2) {
return "red";
}
if (typeNum === 3) {
return "green";
}
if (typeNum === 4) {
return "blue";
}
if (typeNum === 5) {
return "orange";
}
if (typeNum === 6) {
return "violet";
}
return "black";
}