-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
33 lines (31 loc) · 1.08 KB
/
main.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
const input = document.getElementById("search");
const result = document.getElementById("results")
function videoYoutube() {
result.innerHTML = `<img id="loading" src="loading.gif">`
fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&key=${apiKey}&q=${input.value}`)
.then(function(data){
return data.json().then(function(data){
result.innerHTML = ""
if(data.items.length === 0){
result.innerHTML = `Nenhum resuldado encontrado :( `
}else{
for (const item of data.items){
result.innerHTML += `
<a href="https://www.youtube.com/watch?v=${item.id.videoId}">
<img src="${item.snippet.thumbnails.default.url}">
<div class="description">
<h3>${item.snippet.title}</h3>
<p class="description">${item.snippet.description}</p>
</div>
</a>`
}
if(input.value.length === 0){
result.innerHTML = ""
}
}})
}).catch(function(error){
result.innerHTML = `${error}<p>
Ora bolas!A busca retornou esse errinho aí.</p>`
})
}
input.addEventListener("keyup", videoYoutube)