-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
131 lines (81 loc) · 3.29 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
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
let api = `AIzaSyAFQdVXTxCNUp2eLvMKeIKgYjloNWC_Xbc`;
let getData=async() =>{
try{
let query =document.getElementById("query").value;
let res = await fetch(`https://youtube.googleapis.com/youtube/v3/search?q=${query}&key=AIzaSyCMC229kOy1sG5CrMN5-WJlhelZc0JJoPQ&part=snippet&maxResults=20®ionCode=IN`)
let {items} = await res.json()
let array_of_videos = items;
appendvedio(array_of_videos)
}catch(err){
}
};
let appendvedio = (data) =>{
document.getElementById("search_video").innerHTML=null
document.getElementById("result").innerText="Search Result..."
data.forEach(({snippet:{title,thumbnails:{high:{url}}}, id:{videoId}})=>{
let div = document.createElement('div')
div.setAttribute("id","container")
let data1={
snippet1:title,
videoId1:videoId,
}
div.onclick = () => {
localStorage.setItem("clicked",JSON.stringify(data1))
window.location.href="youtube.html"
}
// let iframe=document.createElement("iframe")
// iframe.src=`https://www.youtube.com/embed/${videoId}`;
// iframe.width="100%";
// iframe.height="100%"
// iframe.allow="fullscreen"
let image= document.createElement("img")
image.src=url
let name= document.createElement("h5")
name.innerText=title;
div.append(image,name)
document.getElementById("search_video").append(div)
console.log()
// let tittle =ele.snippet.title
// let videoID=ele.id.videoId;
})
}
document.getElementById("image").addEventListener("click",()=>{
window.location.href="index.html"
})
let trending=async() =>{
try{
let res = await fetch(`https://youtube.googleapis.com/youtube/v3/videos?&key=AIzaSyCMC229kOy1sG5CrMN5-WJlhelZc0JJoPQ&part=snippet&maxResults=20&chart=mostPopular®ionCode=IN`)
let {items} = await res.json()
let array_of_videos = items;
console.log(array_of_videos)
appendvedio1(array_of_videos)
}catch(err){
}
};
trending()
let appendvedio1 = (data) =>{
document.getElementById("search_video").innerHTML=null
data.forEach(({snippet:{title,thumbnails:{high:{url}}}, id:{videoId}})=>{
let div = document.createElement('div')
div.setAttribute("id","container")
// let iframe=document.createElement("iframe")
// iframe.src=`https://www.youtube.com/embed/${videoId}`;
// iframe.width="100%";
// iframe.height="80%"
// iframe.allow="fullscreen"
let image= document.createElement("img")
image.src=url
let name= document.createElement("h5")
name.innerText=title;
div.append(image,name)
document.getElementById("search_video").append(div)
let data1={
snippet1:title,
videoId1:videoId,
}
div.onclick = () => {
localStorage.setItem("clicked",JSON.stringify(data1))
window.location.href="youtube.html"
}
})
}