-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
49 lines (39 loc) · 1.57 KB
/
script.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
function navigateTo(page) {
window.location.href = page;
}
function fetchPage(url) {
return fetch(url).then(response => response.text());
}
function parseHTML(html) {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
return doc;
}
function filterItems() {
const searchInput = document.getElementById('searchInput').value.toLowerCase();
const searchResults = document.getElementById('searchResults');
searchResults.innerHTML = '';
const pages = ['escola.html', 'saudacoes.html', 'numeros.html', 'lojas.html', 'hospital.html', 'alfabeto.html']; // Adicione aqui as páginas que deseja pesquisar
if (searchInput === '') {
searchResults.textContent = 'Nenhum ID correspondente encontrado';
return;
}
let promises = pages.map(page => fetchPage(page));
Promise.all(promises).then(responses => {
responses.forEach(response => {
const doc = parseHTML(response);
const gridItems = doc.getElementsByClassName('grid-item-id');
Array.from(gridItems).forEach(item => {
const itemId = item.id.toLowerCase();
if (itemId.includes(searchInput)) {
searchResults.appendChild(item.cloneNode(true));
}
});
});
if (!searchResults.hasChildNodes()) {
searchResults.textContent = 'Nenhum ID correspondente encontrado';
}
}).catch(error => {
console.error('Error fetching pages:', error);
});
}