-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
139 lines (64 loc) · 2.53 KB
/
content.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
import nvbr from "./componnents/navbar.js"
document.getElementById("navbar").innerHTML =nvbr()
import filterbtn from "./componnents/filter.js"
document.getElementById("filtersdiv").innerHTML=filterbtn()
import jump from "./componnents/redirect.js"
document.getElementById("searchbtn").addEventListener("click" , jump())
async function content_show(data){
let parent = document.querySelector(".container")
document.querySelector(".container").innerHTML=null
for(let el of data){
let child = document.createElement("div")
child.className="video"
child.addEventListener("click",function(){
store(el)
})
let channel_picture = await channel(el.snippet.channelId)
child.innerHTML = `
<img src="${el.snippet.thumbnails.high.url}" class="thumbnail" alt="">
<div class="content">
<img src="${channel_picture}" class="channel-icon" alt="">
<div class="info">
<h4 class="title">${el.snippet.title}</h4>
<p class="channel-name">${el.snippet.channelTitle}</p>
</div>
</div> `
parent.append(child)
}
}
const show= async ()=>{
let API_KEYS =["AIzaSyASPLAWmjCPDRoiMtt1AHGQ0TGyRx9wTRU","AIzaSyASPLAWmjCPDRoiMtt1AHGQ0TGyRx9wTRU","AIzaSyBihnXKUmx9h6DHAlTNkrZ-6znzrz3ME1M","AIzaSyA8HVQEsyROLmeZ4P3GhKRCU2BajTnJUNc","AIzaSyAgE8JOY06kJSUxBYYXCGKhQnhx1qD8jdA"]
let num= Math.floor(Math.random()*2)
let API_KEY = API_KEYS[num]
let search = localStorage.getItem("search_term")
let data = await fetch(`https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&q=${search}&key=${API_KEY}`)
data = await data.json()
let actual_data = data.items
console.log(actual_data)
content_show(actual_data)
}
const store =(el)=>{
localStorage.setItem("video_data",JSON.stringify(el))
window.location.href="video.html"
}
show()
const change =async (el)=>{
let value=el.innerHTML
let data = await fetch(`https://youtube.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&q=${value}&key=AIzaSyCGz_8bE32q4NAkjdAXjpAiigBS6z9ZASU`)
data = await data.json()
let actual_data = data.items
console.log(actual_data)
content_show(actual_data)
}
let arr=document.querySelectorAll(".filter-options")
for(let el of arr){
el.addEventListener("click",function(){
change(el)
})
}
const channel= async (channelid)=>{
let g= await fetch ( ` https://www.googleapis.com/youtube/v3/channels?part=snippet&id=${channelid}&key=AIzaSyA8HVQEsyROLmeZ4P3GhKRCU2BajTnJUNc` )
g = await g.json()
let url = await g.items[0].snippet.thumbnails.high.url
return await url
}