-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoutube.js
58 lines (35 loc) · 1.38 KB
/
youtube.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
async function append(){
try{
let query=document.getElementById("query").value
console.log(query)
let url=`https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=20&q=${query}&key=AIzaSyATuAp12OKKitZsSGxEy0OqZnO-EGd1b_k`
let res=await fetch(url)
let data=await res.json()
console.log(data.items)
menu(data.items)
} catch (err){
console.log(err)
}
}
function menu(data){
let container=document.getElementById("container")
data.forEach(({id:{videoId},snippet:{title, thumbnails :{medium :{url}}}}) => {
let div=document.createElement("div");
let thumbnail=document.createElement("img")
thumbnail.src=url;
let h3=document.createElement("h3")
h3.innerText=title;
div.addEventListener("click", () => {
newpage(videoId)
})
div.append(thumbnail,h3)
container.append(div)
})
}
function newpage(data){
let id=data;
localStorage.setItem("videoId",JSON.stringify(id));
window.location.href="playVideo.html";
}
/*
<iframe width="560" height="315" src="https://www.youtube.com/embed/Ae54Lsz5_9A" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> */