-
Notifications
You must be signed in to change notification settings - Fork 0
/
script2.js
236 lines (184 loc) · 7.31 KB
/
script2.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
const api = "api_key=94b3d14bda25053d164683657a0867e7";
//base url of the site
const base_url="https://api.themoviedb.org/3";
const banner_url="https://image.tmdb.org/t/p/original";
const img_url="https://image.tmdb.org/t/p/w500";
//requests for movies data
const requests={
fetchTrending: `${base_url}/trending/all/week?${api}&language=en-US`,
fetchNetflixOrignals:`${base_url}/discover/tv?${api}&with_networks=213`,
fetchActionMovies:`${base_url}/discover/movie?${api}&with_genres=28`,
fetchHorrorMovies:`${base_url}/discover/movie?${api}&with_genres=27`,
fetchRomanceMovies:`${base_url}/discover/movie?${api}&with_genres=10749`,
fetchDocumentaries:`${base_url}/discover/movie?${api}&with_genres=99`,
};
//used to truncate the string
function truncate(str,n){
return str?.length > n ? str.substr(0,n-1) + "..." : str;
}
//banner
fetch(requests.fetchNetflixOrignals)
.then((res) => res.json())
.then((data) => {
console.log(data.results);
//every refresh the movie will be change
const setMovie=
data.results[Math.floor(Math.random() * data.results.length - 1)];
var banner = document.getElementById("banner");
var banner_title=document.getElementById("banner_title");
var banner_desc=document.getElementById("banner_description");
banner.style.backgroundImage =
"url(" + banner_url + setMovie.backdrop_path + ")";
banner_desc.innerText = truncate(setMovie.overview,150);
banner_title.innerText = setMovie.name;
});
//movies rows
fetch(requests.fetchNetflixOriginals)
.then((res) => res.json())
.then((data) =>{
const headrow = document.getElementById("headrow");
const row = document.createElement("div");
row.className = "row";
row.classList.add("netflixrow");
headrow.appendChild(row);
const title = document.createElement("h2");
title.className = "row_title";
title.innerText = "NETFLIX ORIGINALS";
row.appendChild(title);
const row_posters = document.createElement("div");
row_posters.className = "row_posters";
row.appendChild(row_posters);
data.results.forEach((movie) => {
const poster = document.createElement("img");
poster.className = "row_posterLarge";
var s = movie.name.replace(/\s+/g,"");
poster.id = s;
poster.src = img_url + movie.poster_path;
row_posters.appendChild(poster);
});
});
// top rated
fetch(requests.fetchTrending)
.then((res) => res.json())
.then((data) => {
const headrow = document.getElementById("headrow");
const row = document.createElement("div");
row.className = "row";
headrow.appendChild(row);
const title = document.createElement("h2");
title.className = "row_title";
title.innerText = "Top Rated";
row.appendChild(title);
const row_posters = document.createElement("div");
row_posters.className = "row_posters";
row.appendChild(row_posters);
data.results.forEach((movie) => {
console.log(movie);
const poster = document.createElement("img");
poster.className = "row_posterLarge";
var s2 = movie.id;
poster.id = s2;
poster.src = img_url + movie.poster_path;
row_posters.appendChild(poster);
});
});
//action
fetch(requests.fetchActionMovies)
.then((res) => res.json())
.then((data)=> {
const headrow = document.getElementById("headrow");
const row = document.createElement("div");
row.className = "row";
headrow.appendChild(row);
const title = document.createElement("h2");
title.className="row_title";
title.innerText="Action Movies";
row.appendChild(title);
const row_posters = document.createElement("div");
row_posters.className = "row_posters";
row.appendChild(row_posters);
data.results.forEach((movie)=>{
console.log(movie);
const poster = document.createElement("img");
poster.className = "row_poster";
var s2 = movie.id;
poster.id=s2;
poster.src=img_url + movie.backdrop_path;
row_posters.appendChild(poster);
});
});
//Horror
fetch(requests.fetchHorrorMovies)
.then((res) => res.json())
.then((data)=> {
const headrow = document.getElementById("headrow");
const row = document.createElement("div");
row.className = "row";
headrow.appendChild(row);
const title = document.createElement("h2");
title.className="row_title";
title.innerText="Horror Movies";
row.appendChild(title);
const row_posters = document.createElement("div");
row_posters.className = "row_posters";
row.appendChild(row_posters);
data.results.forEach((movie)=>{
console.log(movie);
const poster = document.createElement("img");
poster.className = "row_poster";
var s2 = movie.id;
poster.id=s2;
poster.src=img_url + movie.backdrop_path;
row_posters.appendChild(poster);
});
});
//Romancemovies
fetch(requests.fetchRomanceMovies)
.then((res) => res.json())
.then((data)=> {
const headrow = document.getElementById("headrow");
const row = document.createElement("div");
row.className = "row";
headrow.appendChild(row);
const title = document.createElement("h2");
title.className="row_title";
title.innerText="Romance Movies";
row.appendChild(title);
const row_posters = document.createElement("div");
row_posters.className = "row_posters";
row.appendChild(row_posters);
data.results.forEach((movie)=>{
console.log(movie);
const poster = document.createElement("img");
poster.className = "row_poster";
var s2 = movie.id;
poster.id=s2;
poster.src=img_url + movie.backdrop_path;
row_posters.appendChild(poster);
});
});
//Documentry
fetch(requests.fetchDocumentaries)
.then((res) => res.json())
.then((data)=> {
const headrow = document.getElementById("headrow");
const row = document.createElement("div");
row.className = "row";
headrow.appendChild(row);
const title = document.createElement("h2");
title.className="row_title";
title.innerText="Documentaries";
row.appendChild(title);
const row_posters = document.createElement("div");
row_posters.className = "row_posters";
row.appendChild(row_posters);
data.results.forEach((movie)=>{
console.log(movie);
const poster = document.createElement("img");
poster.className = "row_poster";
var s2 = movie.id;
poster.id=s2;
poster.src=img_url + movie.backdrop_path;
row_posters.appendChild(poster);
});
});