-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
117 lines (84 loc) · 3.3 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
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
const buttons = document.querySelectorAll('.button');
const list = document.getElementById('list');
list.classList.add('catalog');
// Mapeamento dos IDs dos botões para funções
const buttonFunctions = {
button1: fetchConteudos,
button2: fetchMetaversos,
button3: fetchFerramentas,
button4: fetchLaboratorios
};
buttons.forEach(button => {
button.addEventListener('click', () => {
const buttonId = button.id;
// Chama a função correspondente com base no ID do botão
if (buttonFunctions.hasOwnProperty(buttonId)) {
const fetchDataFunction = buttonFunctions[buttonId];
fetchDataFunction();
}
});
});
function fetchConteudos(){
// Limpa a lista atual
list.innerHTML = '';
let url = 'https://snowy-feather-log.glitch.me/conteudos';
getLabels(url);
}
function fetchMetaversos(){
list.innerHTML = '';
let ResourcesArray = [];
let url = 'https://snowy-feather-log.glitch.me/metaversos';
getLabels(url);
}
function fetchFerramentas(){
list.innerHTML = '';
let url = 'https://snowy-feather-log.glitch.me/ferramentas';
getLabels(url);
}
function fetchLaboratorios(){
list.innerHTML = '';
let url = 'https://snowy-feather-log.glitch.me/laboratorios';
getLabels(url);
}
function getLabels(url){
fetch(url)
.then((response) => response.json())
.then(json => {
const data = json;
const catalogo = data;
console.log(catalogo);
catalogo.forEach(item => {
var catalogElement = document.createElement('div');
catalogElement.classList.add('catalogElement');
var imageElement = document.createElement('div');
imageElement.classList.add('image');
imageElement.innerHTML = `<a href="${item.linkDoConteúdo}" target="_blank"><img src="${item.linkDaImagem}"></img></a>`;
catalogElement.appendChild(imageElement);
var textContent = document.createElement('div');
textContent.classList.add('textContent');
var lineContainer = document.createElement('div');
lineContainer.classList.add('lineContainer');
var titleElement = document.createElement('div');
titleElement.innerHTML = `<a href="${item.linkDoConteúdo}" target="_blank"><h3>${item.nome}</h3></a>`;
lineContainer.appendChild(titleElement);
if (item.linkDoTutorial != ""){
var tutorialButton = document.createElement('div');
tutorialButton.innerHTML = `<a href="${item.linkDoTutorial}" target="_blank"><div class="tutorialButton">Tutorial</div></a>`;
lineContainer.appendChild(tutorialButton);
}
textContent.appendChild(lineContainer);
var descriptionElement = document.createElement('p');
descriptionElement.innerHTML = `<a href="${item.linkDoConteúdo}" target="_blank"><p>${item.descrição}</p></a>`;
textContent.appendChild(descriptionElement);
var tagsElement = document.createElement('p');
tagsElement.classList.add('tags');
tagsElement.innerHTML += item.tags;
textContent.appendChild(tagsElement);
catalogElement.appendChild(textContent);
list.appendChild(catalogElement);
list.innerHTML += "<hr>";
});
});
}
// Simula o clique no botão 1 ao abrir a página
fetchConteudos();