forked from khushal2891/Netflix-Clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotfux.js
678 lines (517 loc) · 20.6 KB
/
notfux.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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
const array = [
{
name: '300',
logo: 'assets/logos/300-logo.png',
img: 'assets/pictures/300.jpeg',
poster: 'assets/background/300.png',
trailer: ['assets/trailers/300.mp4'],
genre: ['movies']
},
{
name: 'Avengers: Endgame',
logo: 'assets/logos/avengers-endgame-logo.png',
img: 'assets/pictures/avengers-endgame.png',
poster: 'assets/background/endgame.png',
trailer: [
'assets/trailers/avengers-endgame-1.mp4',
'assets/trailers/avengers-endgame-2.mp4'
],
genre: ['movies']
},
{
name: 'Avengers: Infinity War',
logo: 'assets/logos/avengers-infinity-logo.png',
img: 'assets/pictures/infinity-war.png',
poster: 'assets/background/infinity-war.png',
trailer: [
'assets/trailers/avengers-infinity-war.mp4',
'assets/trailers/avengers-infinity-war-2.mp4'
],
genre: ['movies']
},
{
name: 'The Big O',
logo: 'assets/logos/big-o-logo.png',
img: 'assets/pictures/big-o.png',
poster: 'assets/background/big-o.png',
trailer: [
'assets/trailers/big-o.mp4',
'assets/trailers/big-o-opening-1.mp4',
'assets/trailers/big-o-opening-2.mp4',
'assets/trailers/big-o-credits.mp4'
],
genre: ['anime', 'series']
},
{
name: 'Cowboy Bebop',
logo: 'assets/logos/bebop-logo.png',
img: 'assets/pictures/cowboy-bebop.jpg',
poster: 'assets/background/bebop.png',
trailer: [
'assets/trailers/cowboy-bebop-opening.mp4',
'assets/trailers/bebop-four.mov',
'assets/trailers/bebop-bang.mov',
'assets/trailers/bebop-one.mov',
'assets/trailers/bebop-bass.mov'
],
genre: ['anime', 'series']
},
{
name: 'Game Of Thrones',
logo: 'assets/logos/game-of-thrones-logo.png',
img: 'assets/pictures/game-of-thrones.png',
poster: 'assets/background/game-of-thrones.png',
trailer: [
'assets/trailers/game-of-thrones-s1.mp4',
'assets/trailers/game-of-thrones-s2.mp4',
'assets/trailers/game-of-thrones-s3.mp4',
'assets/trailers/game-of-thrones-s4.mp4',
'assets/trailers/game-of-thrones-s5.mp4',
'assets/trailers/game-of-thrones-s6.mp4',
'assets/trailers/game-of-thrones-s7.mp4',
'assets/trailers/game-of-thrones-s8-1.mp4',
'assets/trailers/game-of-thrones-s8-2.mp4',
'assets/trailers/game-of-thrones-s8-3.mp4',
'assets/trailers/game-of-thrones-s8-4.mp4',
'assets/trailers/game-of-thrones-s8-5.mp4'
],
genre: ['originals', 'series', 'TV Series']
},
{
name: 'Ghost In The Shell: Stand Alone Complex',
logo: 'assets/logos/ghost-shell-logo.png',
img: 'assets/pictures/ghost-in-the-shell.png',
poster: 'assets/background/ghost-in-the-shell.png',
trailer: [
'assets/trailers/ghost-first-gig.mp4',
'assets/trailers/ghost-in-the-shell.mp4',
'assets/trailers/ghost-second-gig.mp4'
],
genre: ['anime', 'series']
},
{
name: '.Hack//Sign',
logo: 'assets/logos/hack-sign-logo.png',
img: 'assets/pictures/hack-sign.jpg',
poster: 'assets/background/hack-sign.png',
trailer: [
'assets/trailers/hack-sign-opening.mp4',
'assets/trailers/hack-sign-credits.mp4'
],
genre: ['anime', 'series']
},
{
name: 'Knights Of Sidonia',
logo: 'assets/logos/sidonia-logo.png',
img: 'assets/pictures/knights-of-sidonia.png',
poster: 'assets/background/knights-of-sidonia.png',
trailer: [
'assets/trailers/knights-sidonia-1.mp4',
'assets/trailers/knights-sidonia-2.mp4'
],
genre: ['anime', 'originals', 'series']
},
{
name: 'Mass Effect: Legendary Edition',
logo: 'assets/logos/mass-effect-logo.png',
img: 'assets/pictures/mass-effect-legendary.png',
poster: 'assets/background/mass-effect-legendary.png',
trailer: [
'assets/trailers/mass-effect-legendary.mp4',
'assets/trailers/mass-effect-legendary-short.mp4',
'assets/trailers/mass-effect-2.mp4',
'assets/trailers/mass-effect-3.mp4',
'assets/trailers/mass-effect-trilogy.mp4'
],
genre: ['games']
},
{
name: 'Neon Genesis Evangelion',
logo: 'assets/logos/evangelion-logo.png',
img: 'assets/pictures/evangelion.png',
poster: 'assets/background/evangelion.png',
trailer: [
'assets/trailers/evangelion.mp4',
'assets/trailers/evangelion-opening.mp4',
'assets/trailers/evangelion-credits.mp4'
],
genre: ['anime', 'series']
},
{
name: 'Rome',
logo: 'assets/logos/rome-logo.png',
img: 'assets/pictures/rome.png',
poster: 'assets/background/rome.png',
trailer: [
'assets/trailers/rome-1.mp4',
'assets/trailers/rome-opening.mp4',
],
genre: ['originals', 'series', 'TV Series']
},
{
name: 'Samurai Champloo',
logo: 'assets/logos/champloo-logo.png',
img: 'assets/pictures/samurai-champloo.jpg',
poster: 'assets/background/samurai-champloo.png',
trailer: [
'assets/trailers/samurai-champloo.mp4',
'assets/trailers/samurai-champloo-opening.mp4',
'assets/trailers/samurai-champloo-funimation.mp4'
],
genre: ['anime', 'series']
},
{
name: 'StarCraft 2',
logo: 'assets/logos/starcraft2-logo.png',
img: 'assets/pictures/starcraft2.png',
poster: 'assets/background/starcraft2.png',
trailer: [
'assets/trailers/starcraft2-wings-of-liberty-1.mp4',
'assets/trailers/starcraft2-wings-of-liberty-2.mp4',
'assets/trailers/starcraft2-wings-of-liberty-3.mp4',
'assets/trailers/starcraft2-heart-of-the-swarm-1.mp4',
'assets/trailers/starcraft2-heart-of-the-swarm-2.mp4',
'assets/trailers/starcraft2-legacy-of-the-void-1.mp4',
'assets/trailers/starcraft2-legacy-of-the-void-2.mp4',
'assets/trailers/starcraft2-legacy-of-the-void-3.mp4'
],
genre: ['games']
},
{
name: 'Transcendent Man',
logo: 'assets/logos/transcendent-man-logo.png',
img: 'assets/pictures/transcendent-man.png',
poster: 'assets/background/transcendent-man.png',
trailer: ['assets/trailers/transcendent-man.mp4'],
genre: ['movies']
},
{
name: 'Trigun',
logo: 'assets/logos/trigun-logo.png',
img: 'assets/pictures/trigun.jpg',
poster: 'assets/background/trigun.png',
trailer: [
'assets/trailers/trigun.mp4',
'assets/trailers/trigun-opening.mp4',
'assets/trailers/trigun-credits.mp4'
],
genre: ['anime', 'series']
},
{
name: 'Troy',
logo: 'assets/logos/troy-logo.png',
img: 'assets/pictures/troy.png',
poster: 'assets/background/troy.png',
trailer: [
'assets/trailers/troy-1.mp4',
'assets/trailers/troy-2.mp4'
],
genre: ['movies']
},
{
name: 'The Witcher 3: Wild Hunt',
logo: 'assets/logos/witcher-logo.png',
img: 'assets/pictures/witcher3.png',
poster: 'assets/background/witcher3.png',
trailer: [
'assets/trailers/witcher-blood-and-wine.mp4',
'assets/trailers/witcher-bruxa.mp4',
'assets/trailers/witcher-game-of-year.mp4',
'assets/trailers/witcher-hearts-of-stone.mp4',
'assets/trailers/witcher-legend.mp4',
'assets/trailers/witcher-monsters.mp4',
'assets/trailers/witcher-nextgen.mp4'
],
genre: ['games']
}
];
const buttons = document.querySelectorAll("button");
const caret = document.querySelector(".fa-caret-down");
const catalogue = document.querySelector(".catalogue"); //parent to all carousels on document
const full = document.documentElement; // used for full screen.
const header = document.querySelector("header");
const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); //checks if mobile device
const showcase = document.querySelector(".showcase"); //background where video displays
const title = document.querySelector(".showcase-title"); //video logo section
const toggle = document.querySelector(".togglebtn");
const video = document.getElementById("video");
const watchList = document.getElementById("list"); //watchlist button
let genre = ['watchlist', 'originals', 'movies', 'series', 'games', 'anime', 'TV Series']; //used to create carousel genres
let num = randomRange(0, array.length - 1); //sets random number within array size
let opaque = 1;
let opaqueInt;
let playButton = document.getElementById("play-button"); //play || pause
let playIcon = document.getElementById("play-icon"); //play || pause ,image
let selection; //will hold array of class .selection items
let showcaseImg = document.querySelector(".showcase-img"); //for video title logos
let trailers; //for video source selection
//arranges array length
function arrange() {
//refreshes array length in case changes were made
selection = document.querySelectorAll(".selection");
for(let i = 0; i < selection.length; i++) {
selection[i].addEventListener("click", function() {
for(let j = 0; j < array.length; j++) {
//selects correct array item position by matching the items' names
if(array[j].name == selection[i].children[1].textContent) {
num = j;
theater();
if(playButton.textContent == "Play") {
setTimeout(function() {
showcaseUI();
}, 2500); //waits 2.5 secs to show poster image
} else {
showcaseUI();
}
}
}
});
};
}
//creates objects in webpage from array
function display() {
for(let i = 0; i < genre.length; i++) {
let outer = document.createElement("div");
outer.classList.add("category");
let h3 = document.createElement("h3");
h3.textContent = genre[i][0].toUpperCase() + genre[i].slice(1); //makes 1st letter Capital
h3.id = genre[i]; //set id for the h3 title
let inner = document.createElement("div");
inner.classList.add("carousel");
outer.append(h3);
outer.append(inner);
catalogue.append(outer);
array.forEach(obj => {
let anchor = document.createElement("a");
anchor.href = "#trailer";
let figure = document.createElement("figure");
figure.classList.add("selection");
let figCaption = document.createElement("figcaption");
figCaption.textContent = obj.name;
let img = new Image();
img.src = obj.img;
img.setAttribute('draggable', false);
for(let j = 0; j < obj.genre.length; j++) {
if(obj.genre[j] == genre[i]) {
inner.append(anchor);
}
}
anchor.append(figure);
figure.append(img);
figure.append(figCaption);
});
}
for(let h = 0; h < catalogue.children.length; h++) {
//searches in document for watchlist carousel
if(catalogue.children[h].children[0].textContent == "Watchlist") {
//if watchlist is empty
if(catalogue.children[h].children[1].length == undefined) {
catalogue.children[h].style.display = "none"; //it is hidden
}
}
};
}
function toggleFullScreen(web) {
let requestMethod = web.requestFullScreen || web.webkitRequestFullScreen || web.mozRequestFullScreen || web.msRequestFullScreen;
let cancelMethod = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen;
// Check if we're already in fullscreen mode
if (document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {
if (cancelMethod) { // Exit fullscreen mode
cancelMethod.call(document);
}
} else { // Enter fullscreen mode
if (requestMethod) {
requestMethod.call(web);
} else if (typeof window.ActiveXObject !== "undefined") { // Older IE.
let wscript = new ActiveXObject("WScript.Shell");
if (wscript !== null) {
wscript.SendKeys("{F11}");
}
}
}
}
//Returns a random number within a chosen range
function randomRange(min,max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
//Math.floor() rounds down to the nearest whole number e.i. 10 = 0 - 9
//Math.random() returns a random decimal between 0 - 0.99
}
//play or pause, video & button
function showcaseUI() {
header.style.transition = "2.5s ease-in-out 0ms";
header.style.marginTop = "0";
header.style.marginBottom = "0";
showcase.style.minHeight = "70vh";
title.style.paddingTop = "50vh";
clearInterval(opaqueInt);
if(video.paused) {
if(playButton.textContent == "Pause") {
setTimeout(function() {
video.play();
}, 2500); //waits 2.5 secs
} else {
video.play();
}
//checks if trailer exists
if(array[num].trailer != 0) {
playButton.textContent = "Pause";
playIcon.src = 'assets/pause.png';
header.style.transition = "5s ease-in-out 1000ms";
header.style.marginTop = "-25vh";
header.style.marginBottom = "25vh";
showcase.style.minHeight = "90vh";
if(isMobile) { //if mobile and tablets
title.style.paddingTop = "69vh";
} else {
title.style.paddingTop = "80vh"; //lowers title graphic more
if(opaque >= 1) { //makes buttons transparent
opaqueInt = setInterval(function() {
if(opaque <= 0.00) {
clearInterval(opaqueInt);
}
opaque -= Math.round(0.05 * 100) / 100;
for(b = 0; b < buttons.length; b++) {
buttons[b].style.opacity = `${opaque}`;
}
}, 250);
}
}
}
} else {
video.pause();
playButton.textContent = "Play";
playIcon.src = 'assets/play.png';
if(opaque < 1) { //if buttons are transparent
opaqueInt = setInterval(function() {
if(opaque >= 1) {
clearInterval(opaqueInt);
}
opaque += Math.round(0.05 * 100) / 100;
for(b = 0; b < buttons.length; b++) {
buttons[b].style.opacity = `${opaque}`;
}
}, 100);
}
}
}
//selects item to display and play
function theater() {
//displays corresponding item logo
showcaseImg.src = array[num].logo;
showcaseImg.style.height = '52px';
//allows for multiple object array trailers to randomly play
video.poster = array[num].poster;
if(array[num].name == 'Game Of Thrones') {
trailers = randomRange(0, 6); //no random spoilers
} else {
trailers = randomRange(0, array[num].trailer.length - 1); //random video selection
}
video.src = array[num].trailer[trailers];
}
//Best view for portrait or landscape mode?
function viewStyle() {
if(window.innerHeight > window.innerWidth) {
video.style.objectFit = "fill"; //portrait mode
//this fixes a bug in mobile
if(isMobile && playButton.textContent == "Pause") {
video.play();
}
} else {
video.style.objectFit = "cover"; //landscape mode
}
}
caret.addEventListener("click", function() {
toggleFullScreen(full);
});
showcase.addEventListener("click", function() {
showcaseUI();
});
toggle.addEventListener("click", function() {
toggleFullScreen(full);
});
//adds item to user watchlist
watchList.addEventListener("click", function() {
video.play(); //always triggers pause once showcaseUI() function runs
let anchor = document.createElement("a");
anchor.href = "#trailer";
let figure = document.createElement("figure");
figure.classList.add("selection");
let figCaption = document.createElement("figcaption");
figCaption.textContent = array[num].name;
let img = new Image();
img.src = array[num].img;
anchor.append(figure);
figure.append(img);
figure.append(figCaption);
for(let h = 0; h < catalogue.children.length; h++) {
//locates watchlist carousel in document
if(catalogue.children[h].children[0].textContent == "Watchlist") {
catalogue.children[h].style.display = "block"; //visibly displays carousel
for(let j = 0; j < catalogue.children[h].children[1].children.length; j++) {
//checks watchlist array for previous copies of current item
if(anchor.children[0].children[1].textContent == catalogue.children[h].children[1].children[j].children[0].children[1].textContent) {
//removes duplicate from array
catalogue.children[h].children[1].children[j].remove();
}
}
//append current selection at the beginning of the list
catalogue.children[h].children[1].insertBefore(anchor, catalogue.children[h].children[1].children[0]);
}
};
arrange();
});
window.addEventListener("mousemove", function() {
if(!video.paused && !isMobile) { //only runs if video is playing & not mobile device
clearInterval(opaqueInt);
if(opaque <= 1) {
opaqueInt = setInterval(function() {
if(opaque >= 1) {
clearInterval(opaqueInt);
}
opaque += Math.round(0.05 * 100) / 100;
for(b = 0; b < buttons.length; b++) {
buttons[b].style.opacity = `${opaque}`;
}
}, 100);
setTimeout(function() {
if(!video.paused && opaque >= 1) {
clearInterval(opaqueInt);
opaqueInt = setInterval(function() {
if(opaque <= 0.00) {
clearInterval(opaqueInt);
}
opaque -= Math.round(0.05 * 100) / 100;
for(b = 0; b < buttons.length; b++) {
buttons[b].style.opacity = `${opaque}`;
}
}, 250);
}
}, 5000); //waits 5 seconds
}
}
});
window.addEventListener("resize", function() {
header.style.transition = "0s ease-in-out 0ms"; //header width changes occur fast on screen resize
//timeout fixes a bug on mobile
setTimeout(function() {
viewStyle();
}, 25);
});
video.onended = function () {
trailers++
if(trailers > array[num].trailer.length - 1) {
trailers = 0;
}
video.src = array[num].trailer[trailers];
setTimeout(function() {
if(playButton.textContent == "Pause") {
video.play();
}
}, 1500); //waits 1.5 sec
};
window.onload = function() {
viewStyle();
display();
theater();
arrange();
};