-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
360 lines (325 loc) · 11.7 KB
/
Copy pathscript.js
File metadata and controls
360 lines (325 loc) · 11.7 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
let pesoBackend = 0;
let pesoFrontend = 0;
let pesoAnalista = 0;
let prompt =
"Mostre um caminho claro para um usuario que fez um teste de especialidade em tech de forma sucinta em 150 palavras. o resultado foi: ";
let APIurl =
"https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent";
let APIKey = "";
const modal = document.getElementById("modal");
const perguntas = [
{
texto: "Você tem mais interesse em:",
opcoes: [
{
texto: "Criar as partes funcionais de um projeto",
valor: "backend,analista",
},
{
texto: "Criar as parte visuais de um projeto",
valor: "frontend",
},
{
texto: "Analisar e organizar as informações de um projeto",
valor: "analista,backend",
},
],
},
{
texto: "Você se sente a vontade realizando tarefas no console do computador?",
opcoes: [
{ texto: "Sim", valor: "backend,analista" },
{ texto: "Não", valor: "frontend" },
],
},
{
texto: "Qual tarefa te parece mais interessante?",
opcoes: [
{ texto: "Resolver problemas de software", valor: "backend" },
{
texto: "Criar o layout de uma aplicação/site",
valor: "frontend",
},
{ texto: "Organizar informações", valor: "analista" },
],
},
{
texto: "Você se sente a vontade usando um computador com Linux?",
opcoes: [
{ texto: "Sim", valor: "backend,analista" },
{ texto: "Não", valor: "frontend" },
],
},
{
texto: "Qual dessas habilidades você tem maior proficiência?",
opcoes: [
{ texto: "Resolução de problemas", valor: "backend" },
{ texto: "Criatividade", valor: "frontend" },
{ texto: "Análise", valor: "analista" },
],
},
{
texto: "Que tipo de sintaxe de linguagem você gosta?",
opcoes: [
{ texto: "Verbosa", valor: "backend" },
{ texto: "Simples", valor: "analista" },
],
},
{
texto: "O que você acha mais interessante?",
opcoes: [
{ texto: "Desenvolver funcionalidades", valor: "backend" },
{ texto: "Criar interfaces visuais", valor: "frontend" },
{ texto: "Analisar dados", valor: "analista" },
],
},
{
texto: "Qual linguagem você prefere?",
opcoes: [
{ texto: "Java", valor: "backend" },
{ texto: "JavaScript", valor: "frontend" },
{ texto: "PHP", valor: "backend,frontend" },
],
},
{
texto: "Você gosta de trabalhar com instalação e configurações?",
opcoes: [
{ texto: "Sim", valor: "backend" },
{ texto: "Não", valor: "frontend" },
],
},
{
texto: "Você é uma pessoa que gosta de sistemas com visuais modernos?",
opcoes: [
{ texto: "Sim", valor: "frontend" },
{ texto: "Não", valor: "backend,analista" },
],
},
];
let perguntaAtual = 0;
function fadeOut(element, callback) {
element.style.transition = "opacity 0.4s";
element.style.opacity = 0;
setTimeout(() => {
if (callback) callback();
}, 400);
}
function fadeIn(element) {
element.style.transition = "opacity 0.4s";
element.style.opacity = 0;
setTimeout(() => {
element.style.opacity = 1;
}, 10);
}
function atualizarPergunta() {
const container = document.getElementById("pergunta-container");
const app = document.querySelector(".app");
if (!container) return;
fadeOut(container, async () => {
container.innerHTML = "";
app.style.width = "600px";
app.style.height = "300px";
app.style.marginRight = "0";
if (perguntaAtual < perguntas.length) {
container.style.display = "block";
const pergunta = perguntas[perguntaAtual];
const titulo = document.createElement("h3");
titulo.textContent = `Pergunta ${perguntaAtual + 1}: ${
pergunta.texto
}`;
titulo.style.marginBottom = "24px";
container.appendChild(titulo);
pergunta.opcoes.forEach((opcao, idx) => {
const label = document.createElement("label");
label.style.display = "block";
label.style.marginBottom = "16px";
const input = document.createElement("input");
input.type = "radio";
input.name = `pergunta${perguntaAtual + 1}`;
input.value = opcao.valor;
label.appendChild(input);
label.appendChild(document.createTextNode(" " + opcao.texto));
container.appendChild(label);
});
const btn = document.createElement("button");
btn.textContent = "Próxima";
btn.className = "submit-button";
btn.style.marginTop = "32px";
btn.onclick = () => {
const selecionado = container.querySelector(
'input[type="radio"]:checked'
);
if (selecionado) {
const valores = selecionado.value.split(",");
valores.forEach((v) => {
if (v.trim() === "backend") pesoBackend++;
if (v.trim() === "frontend") pesoFrontend++;
if (v.trim() === "analista") pesoAnalista++;
});
perguntaAtual++;
atualizarPergunta();
} else {
alert("Selecione uma opção!");
}
};
container.appendChild(btn);
} else {
let resultado = "";
let imgSrc = "";
let alt = "";
if (pesoBackend > pesoFrontend && pesoBackend > pesoAnalista) {
resultado = "Backend";
imgSrc = "/img/cyborg.webp";
alt = "Backend";
} else if (
pesoFrontend > pesoBackend &&
pesoFrontend > pesoAnalista
) {
resultado = "Frontend";
imgSrc = "/img/johnnybravo.webp";
alt = "Frontend";
} else if (
pesoAnalista > pesoBackend &&
pesoAnalista > pesoFrontend
) {
resultado = "Analista de Dados";
imgSrc = "/img/dexter.webp";
alt = "Analista de Dados";
} else {
resultado = "Generalista de TI";
imgSrc = "/img/descubra.webp";
alt = "Generalista de TI";
}
window.slotFinalText = resultado;
window.slotFinalImage = imgSrc;
window.slotFinalAlt = alt;
container.style.display = "none";
if (modal) {
modal.classList.add("active");
}
}
fadeIn(container);
});
}
const closeModalBtn = document.getElementById("closeModal");
if (closeModalBtn) {
closeModalBtn.addEventListener("click", () => {
const modal = document.getElementById("modal");
modal.classList.remove("active");
const finalResult = window.slotFinalText || "Resultado não disponível";
const finalImgSrc = window.slotFinalImage || null;
const finalAlt = window.slotFinalAlt || null;
showLoadingState(finalResult, finalImgSrc, finalAlt);
callAPI(`${prompt} ${finalResult}`).then((text) => {
displayResult(text);
});
});
}
function showLoadingState(resultado, imgSrc, alt) {
const resultContainer = document.querySelector("#result");
const container = document.getElementById("pergunta-container");
const heading = document.querySelector("#heading");
const main = document.querySelector("main");
const app = document.querySelector(".app");
heading.style.display = "none";
main.style.display = "flex";
main.style.flexDirection = "row";
main.style.justifyContent = "center";
main.style.alignItems = "flex-start";
app.style.width = "400px";
app.style.height = "auto";
app.style.transition = "width 0.5s ease-in";
app.style.marginRight = "50px";
app.style.justifyContent = "start";
app.style.marginTop = "140px";
container.style.display = "flex";
container.style.flexDirection = "column";
container.style.alignItems = "center";
container.innerHTML = "";
const tituloResultado = document.createElement("strong");
tituloResultado.textContent = `Seu perfil é: ${resultado}`;
tituloResultado.style.fontSize = "1.5rem";
tituloResultado.style.marginTop = "20px";
container.appendChild(tituloResultado);
if (imgSrc) {
const img = document.createElement("img");
img.src = imgSrc;
img.alt = alt;
img.style.maxWidth = "220px";
img.style.marginTop = "24px";
container.appendChild(img);
if (resultado === "Generalista de TI") {
setTimeout(() => {
img.src = "/img/edward.png";
}, 2500);
}
}
resultContainer.style.backgroundColor = "#6272A4";
resultContainer.style.padding = "20px";
resultContainer.style.borderRadius = "8px";
resultContainer.style.width = "500px";
resultContainer.style.transition = "all 0.6s ease";
resultContainer.style.marginTop = "120px";
resultContainer.innerHTML = "Carregando dicas...";
}
function displayResult(text) {
const resultContainer = document.querySelector("#result");
const parseText = marked.parse(text);
resultContainer.innerHTML = parseText;
const paragraphs = resultContainer.querySelectorAll("p");
paragraphs.forEach((paragraph) => {
paragraph.style.color = "#dedfe3ff";
paragraph.style.fontSize = "16px";
paragraph.style.lineHeight = "1.6";
});
const strongs = resultContainer.querySelectorAll("strong");
strongs.forEach((strong) => {
strong.style.color = "#ffffffff";
strong.style.fontWeight = "bold";
});
const olists = resultContainer.querySelectorAll("ol");
olists.forEach((olist) => {
olist.style.paddingLeft = "20px";
olist.style.marginBottom = "15px";
olist.style.listStyleType = "decimal";
});
const ulists = resultContainer.querySelectorAll("ul");
ulists.forEach((ulist) => {
ulist.style.paddingLeft = "20px";
ulist.style.marginBottom = "15px";
ulist.style.listStyleType = "disc";
});
const listItems = resultContainer.querySelectorAll("li");
listItems.forEach((item) => {
item.style.marginBottom = "6px";
item.style.color = "#dedfe3ff";
item.style.fontSize = "15px";
});
}
async function callAPI(prompt) {
try {
const response = await fetch(APIurl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-goog-api-key": `${APIKey}`,
},
body: JSON.stringify({
contents: [
{
parts: [
{
text: prompt,
},
],
},
],
}),
});
const data = await response.json();
console.log(data.candidates[0].content.parts[0].text);
return data.candidates[0].content.parts[0].text;
} catch (error) {
console.error("Erro ao obter resposta:", error);
}
}