Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
86 lines (69 loc) · 2.64 KB
/
Copy pathscript.js
File metadata and controls
86 lines (69 loc) · 2.64 KB
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
import axios from "axios";
const containerVideos = document.querySelector(".videos__container");
async function buscarEMostrarVideos() {
const urlVideos = import.meta.env.PROD
? "https://gist.githubusercontent.com/antonio-evaldo/e8a63621b51c883931eb3fa3a3eca990/raw/12f5c46ee6dd00d03c051adadaf341e06452cea0/videos.txt"
: "http://localhost:3000/videos";
try {
const busca = await axios.get(urlVideos);
const videos = busca.data;
videos.forEach((video) => {
if (video.categoria == "") {
throw new Error("Vídeo não tem categoria");
}
containerVideos.innerHTML += `
<li class="videos__item">
<iframe src="${video.url}" title="${video.titulo}" frameborder="0" allowfullscreen></iframe>
<div class="descricao-video">
<img class="img-canal" src="${video.imagem} alt="Logo do Canal">
<h3 class="titulo-video">${video.titulo}</h3>
<p class="titulo-canal">${video.descricao}</p>
<p class="categoria" hidden>${video.categoria} </p>
</div>
</li>
`;
});
} catch (error) {
containerVideos.innerHTML = `<p> Houve um erro ao carregar os vídeos: ${error}</p>`;
}
}
buscarEMostrarVideos();
const barraDePesquisa = document.querySelector(".pesquisar__input");
barraDePesquisa.addEventListener("input", filtrarPesquisa);
function filtrarPesquisa() {
const videos = document.querySelectorAll(".videos__item");
if (barraDePesquisa.value != "") {
for (let video of videos) {
let titulo = video
.querySelector(".titulo-video")
.textContent.toLowerCase();
let valorFiltro = barraDePesquisa.value.toLowerCase();
if (!titulo.includes(valorFiltro)) {
video.style.display = "none";
} else {
video.style.display = "block";
}
}
} else {
for (let video of videos) {
video.style.display = "block";
}
}
}
const botaoCategoria = document.querySelectorAll(".superior__item");
botaoCategoria.forEach((botao) => {
let nomeCategoria = botao.getAttribute("name");
botao.addEventListener("click", () => filtrarPorCategoria(nomeCategoria));
});
function filtrarPorCategoria(filtro) {
const videos = document.querySelectorAll(".videos__item");
for (let video of videos) {
let categoria = video.querySelector(".categoria").textContent.toLowerCase();
let valorFiltro = filtro.toLowerCase();
if (!categoria.includes(valorFiltro) && valorFiltro != "tudo") {
video.style.display = "none";
} else {
video.style.display = "block";
}
}
}