-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (46 loc) · 1.78 KB
/
index.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
/*
Need 2 Things:
(1) Show/Display Videos on Homepage
(2) Search When Something is typed in the search-box
display()
- Show/Display Videos on Homepage
- Based Upon Most Popular Videos
- Should be Called Directly WITHOUT Any Event
(No Hover, No Click , No On Click)
- On Page Load
searchVideo()
- Search When Something is typed in the search-box
- Take the "String" typed in search-box and search on that string
*/
let div = document.getElementById("videodiv");
// (1) Show/Display Videos on Homepage
async function display(){
// q = Popular Videos --> Popular%20Videos (%20 -> Space)
let res = await fetch(`https://youtube.googleapis.com/youtube/v3/search?q=popular%20videos&key=AIzaSyA00OxUbfdfVAjHn-9l48s0t-n_j7CBbNs&maxResults=25`);
let data = await res.json();
for({id:{videoId}}of data.items)
{
let videodiv= document.createElement("iframe")
videodiv.setAttribute("class","mons")
videodiv.src = `https://www.youtube.com/embed/${videoId}`;
videodiv.allow = 'fullscreen'
div.append(videodiv)
}
}
display();
// (2) Search When Something is typed in the search-box
async function searchVideos(){
document.getElementById("videodiv").innerHTML=""; // Empty
let query = document.getElementById("video").value; // Search String/ Query String
//search for videos
let res = await fetch(`https://youtube.googleapis.com/youtube/v3/search?q=${query}&type=video&key=AIzaSyA00OxUbfdfVAjHn-9l48s0t-n_j7CBbNs&maxResults=25`);
let data = await res.json();
for({id:{videoId}}of data.items)
{
let videodiv= document.createElement("iframe")
videodiv.setAttribute("class","mons")
videodiv.src = `https://www.youtube.com/embed/${videoId}`;
videodiv.allow = 'fullscreen'
div.append(videodiv)
}
}