-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (61 loc) · 2.02 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
const videoCardContainer = document.querySelector(".video-container");
let api_key = "AIzaSyBT5EVrmwvj4I2mWW1CuhvGPLeQ-vHDZ7g";
let video_http = "https://www.googleapis.com/youtube/v3/videos?";
let channel_api = "https://www.googleapis.com/youtube/v3/channels?";
fetch(
video_http +
new URLSearchParams({
key: api_key,
part: "snippet",
chart: "mostPopular",
maxResults: 50,
regionCode: "IN",
})
)
.then((res) => res.json())
.then((data) => {
// console.log(data)
data.items.forEach((item) => {
getChannelIcon(item);
});
})
.catch((err) => console.log(err));
const getChannelIcon = (video_data) => {
fetch(
channel_api +
new URLSearchParams({
key: api_key,
part: "snippet",
id: video_data.snippet.channelId,
})
)
.then((res) => res.json())
.then((data) => {
video_data.channelThumbnail =
data.items[0].snippet.thumbnails.default.url;
// console.log(video_data)
makeVideoCard(video_data);
});
const makeVideoCard = (data) => {
videoCardContainer.innerHTML += `
<div class="video" onclick="location.href = 'https://youtube.com/watch?v=${data.id}'">
<img src="${data.snippet.thumbnails.high.url}" class="thumbnail" alt=""/>
<div class="content">
<img src="${data.channelThumbnail}" class="channel-icon" alt="">
<div class="info">
<h4 class="title">${data.snippet.title}</h4>
<p class="channel-name">${data.snippet.channelTitle}</p>
</div>
</div>
</div>`;
};
};
//search bar
const searchInput = document.querySelector('.search-bar')
const searchBtn = document.querySelector('.search-btn');
let searchLink = "https://www.youtube.com/results?search_query=html"
searchBtn.addEventListener('click', () =>{
if(searchInput.value.length){
location.href = searchLink + searchInput.ariaValueMax;
}
})