forked from luiscidrao/preenchedorInfNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
573 lines (475 loc) · 16.8 KB
/
script.js
File metadata and controls
573 lines (475 loc) · 16.8 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
function atualizarTipoTeste() {
const tipoTeste = localStorage.getItem("tipoTeste") || "Teste de Performance";
console.log("Tipo de teste carregado:", tipoTeste);
const elemento1 = document.getElementById("tipoTeste1");
const elemento2 = document.getElementById("tipoTeste2");
console.log("Elemento1 encontrado:", elemento1);
console.log("Elemento2 encontrado:", elemento2);
if (elemento1) elemento1.textContent = tipoTeste;
if (elemento2) elemento2.textContent = tipoTeste;
}
function atualizarNumeroTeste() {
const tipoTeste = localStorage.getItem("tipoTeste") || "Teste de Performance";
let numeroTeste = localStorage.getItem("numeroTeste") || "";
// Se não for Assessment e não houver número, usar "1" como padrão
if (tipoTeste !== "Assessment" && !numeroTeste) {
numeroTeste = "1";
}
const elemento1 = document.getElementById("numeroTeste1");
const elemento2 = document.getElementById("numeroTeste2");
if (elemento1) elemento1.textContent = numeroTeste;
if (elemento2) elemento2.textContent = numeroTeste;
}
function atualizarDataDocumento() {
const dataAtual = new Date();
const dia = String(dataAtual.getDate()).padStart(2, "0");
const mes = String(dataAtual.getMonth() + 1).padStart(2, "0");
const ano = dataAtual.getFullYear();
const dataDefault = `${dia}/${mes}/${ano}`;
const dataDocumento = localStorage.getItem("dataDocumento") || dataDefault;
const dateElement = document.getElementById("dataDocumento");
if (dateElement) dateElement.textContent = dataDocumento;
}
function atualizarInfoCurso() {
const nomeCurso = localStorage.getItem("nomeCurso") || "{Nome do Curso}";
const nomeMateria =
localStorage.getItem("nomeMateria") || "{Nome da Materia}";
const nomeAluno = localStorage.getItem("nomeAluno") || "{Seu Nome}";
const nomeProfessor =
localStorage.getItem("nomeProfessor") || "{Nome do Professor}";
const cursoElement = document.getElementById("nomeCurso");
const materiaElement = document.getElementById("nomeMateria");
const alunoElement = document.getElementById("nomeAluno");
const professorElement = document.getElementById("nomeProfessor");
if (cursoElement) cursoElement.textContent = nomeCurso;
if (materiaElement) materiaElement.textContent = nomeMateria;
if (alunoElement) alunoElement.textContent = nomeAluno;
if (professorElement) professorElement.textContent = nomeProfessor;
}
function atualizarLinksRespostas() {
const container = document.getElementById("respostas-links-container");
if (!container) return;
container.innerHTML = "";
const linksJSON = localStorage.getItem("respostasLinks");
if (linksJSON) {
const links = JSON.parse(linksJSON);
if (links.length > 0) {
const lista = document.createElement("ol");
lista.style.paddingLeft = "2cm";
lista.style.lineHeight = "1.5";
links.forEach((link) => {
const item = document.createElement("li");
const linkElement = document.createElement("a");
linkElement.href = link;
linkElement.textContent = link;
linkElement.target = "_blank"; // Open in new tab
linkElement.style.color = "#0066cc";
linkElement.style.textDecoration = "underline";
item.appendChild(linkElement);
lista.appendChild(item);
});
container.appendChild(lista);
}
}
}
function atualizarTextoLivre() {
const container = document.getElementById("texto-livre-container");
if (!container) return;
container.innerHTML = "";
const texto = localStorage.getItem("textoLivre");
if (texto && texto.trim() !== "") {
const textoDiv = document.createElement("div");
textoDiv.style.padding = "0 2cm";
textoDiv.style.lineHeight = "1.5";
textoDiv.style.marginTop = "20px";
textoDiv.innerHTML = texto;
container.appendChild(textoDiv);
} //
}
function initModeloPage() {
if (
document.getElementById("tipoTeste1") ||
document.getElementById("tipoTeste2") ||
document.getElementById("numeroTeste1") ||
document.getElementById("numeroTeste2")
) {
function atualizarTodoConteudo() {
atualizarTipoTeste();
atualizarNumeroTeste();
atualizarDataDocumento();
atualizarInfoCurso();
atualizarLinksRespostas();
atualizarTextoLivre();
}
window.addEventListener("load", function () {
atualizarTodoConteudo();
const downloadBtn = document.getElementById("download-pdf");
if (downloadBtn) {
downloadBtn.addEventListener("click", downloadPDF);
}
});
window.addEventListener("storage", function (e) {
if (
e.key === "numeroTeste" ||
e.key === "dataDocumento" ||
e.key === "nomeCurso" ||
e.key === "nomeMateria" ||
e.key === "nomeAluno" ||
e.key === "nomeProfessor" ||
e.key === "respostasLinks" ||
e.key === "textoLivre"
) {
atualizarTodoConteudo();
}
});
atualizarTodoConteudo();
}
}
function atualizarNumeracao() {
const respostas = document.querySelectorAll(".resposta-item");
respostas.forEach((item, index) => {
const label = item.querySelector("label");
if (label) {
label.textContent = `${index + 1}:`;
}
});
}
function adicionarCampoResposta() {
const container = document.getElementById("respostas-container");
const novaResposta = document.createElement("div");
novaResposta.className = "resposta-item";
const numeroResposta = container.children.length + 1;
novaResposta.innerHTML = `
<div class="resposta-wrapper">
<label for="resposta${numeroResposta}">${numeroResposta}:</label>
<input type="text" id="resposta${numeroResposta}" class="resposta-input" placeholder="Cole o link aqui" style="width:835px">
<button type="button" class="remover-resposta" style="width:auto;min-width:80px;max-width:150px;">Remover</button>
</div>
`;
container.appendChild(novaResposta);
const botaoRemover = novaResposta.querySelector(".remover-resposta");
botaoRemover.addEventListener("click", function () {
novaResposta.remove();
atualizarNumeracao();
});
}
document.addEventListener("DOMContentLoaded", function () {
const botaoAdicionar = document.getElementById("adicionar-resposta");
if (botaoAdicionar) {
botaoAdicionar.addEventListener("click", adicionarCampoResposta);
}
});
function carregarLinksRespostas() {
const container = document.getElementById("respostas-container");
if (!container) return;
while (container.children.length > 0) {
container.removeChild(container.lastChild);
}
const linksJSON = localStorage.getItem("respostasLinks");
let links = [];
if (linksJSON) {
links = JSON.parse(linksJSON);
}
// Sempre mostrar 16 campos
for (let i = 0; i < 16; i++) {
adicionarCampoResposta();
// Se houver links salvos, preencher o campo
if (links[i]) {
const input = container.lastElementChild.querySelector(".resposta-input");
if (input) input.value = links[i];
}
}
}
function salvarLinksRespostas() {
const inputs = document.querySelectorAll(".resposta-input");
const links = [];
inputs.forEach((input) => {
const valor = input.value.trim();
if (valor) {
links.push(valor);
}
});
localStorage.setItem("respostasLinks", JSON.stringify(links));
}
function initConfigurarPage() {
const salvarNumeroBtn = document.getElementById("salvarNumero");
if (!salvarNumeroBtn) return;
const tipoSalvo = localStorage.getItem("tipoTeste") || "Teste de Performance";
document.getElementById("tipoTeste").value = tipoSalvo;
const numeroSalvo = localStorage.getItem("numeroTeste") || "1";
const numeroTesteInput = document.getElementById("numeroTeste");
// Configurar campo número do teste baseado no tipo salvo
if (tipoSalvo === "Assessment") {
if (!numeroSalvo || numeroSalvo === "1") {
numeroTesteInput.value = "";
} else {
numeroTesteInput.value = numeroSalvo;
}
numeroTesteInput.placeholder = "Opcional para Assessment";
} else {
numeroTesteInput.value = numeroSalvo;
numeroTesteInput.placeholder = "";
}
// Adicionar event listener para mudança no tipo de teste
document.getElementById("tipoTeste").addEventListener("change", function () {
const numeroTesteInput = document.getElementById("numeroTeste");
if (this.value === "Assessment") {
// Limpar o campo quando selecionar Assessment
numeroTesteInput.value = "";
numeroTesteInput.placeholder = "Opcional para Assessment";
} else {
// Restaurar valor padrão para outros tipos
if (!numeroTesteInput.value) {
numeroTesteInput.value = "1";
}
numeroTesteInput.placeholder = "";
}
});
const hoje = new Date();
const dataFormatada = hoje.toISOString().split("T")[0]; // Format YYYY-MM-DD for input type="date"
const dataSalva = localStorage.getItem("dataDocumentoInput") || dataFormatada;
document.getElementById("dataDocumento").value = dataSalva;
document.getElementById("nomeCurso").value =
localStorage.getItem("nomeCurso") || "";
document.getElementById("nomeMateria").value =
localStorage.getItem("nomeMateria") || "";
document.getElementById("nomeAluno").value =
localStorage.getItem("nomeAluno") || "";
document.getElementById("nomeProfessor").value =
localStorage.getItem("nomeProfessor") || "";
carregarLinksRespostas();
initCustomEditor();
const adicionarRespostaBtn = document.getElementById("adicionar-resposta");
if (adicionarRespostaBtn) {
adicionarRespostaBtn.addEventListener("click", function () {
adicionarCampoResposta();
});
}
document.addEventListener("click", function (e) {
if (e.target && e.target.classList.contains("remover-resposta")) {
e.target.closest(".resposta-item").remove();
}
});
salvarNumeroBtn.addEventListener("click", function () {
const tipoTeste = document.getElementById("tipoTeste").value;
const numeroTeste = document.getElementById("numeroTeste").value;
const dataDocumento = document.getElementById("dataDocumento").value;
let validado = true;
if (!tipoTeste) {
alert("Por favor, selecione um tipo de teste.");
validado = false;
}
// Validar número do teste apenas se não for Assessment
if (
tipoTeste !== "Assessment" &&
(!numeroTeste || parseInt(numeroTeste) <= 0)
) {
alert("Por favor, insira um número válido maior que zero.");
validado = false;
}
if (!dataDocumento) {
alert("Por favor, selecione uma data para o documento.");
validado = false;
}
if (validado) {
localStorage.setItem("tipoTeste", tipoTeste);
// Para Assessment, permitir salvar string vazia; para outros, garantir que tenha um valor
const numeroParaSalvar =
tipoTeste === "Assessment" ? numeroTeste || "" : numeroTeste || "1";
localStorage.setItem("numeroTeste", numeroParaSalvar);
localStorage.setItem("dataDocumentoInput", dataDocumento);
const partes = dataDocumento.split("-");
if (partes.length === 3) {
const dataFormatadaDisplay = `${partes[2]}/${partes[1]}/${partes[0]}`;
localStorage.setItem("dataDocumento", dataFormatadaDisplay);
}
localStorage.setItem(
"nomeCurso",
document.getElementById("nomeCurso").value
);
localStorage.setItem(
"nomeMateria",
document.getElementById("nomeMateria").value
);
localStorage.setItem(
"nomeAluno",
document.getElementById("nomeAluno").value
);
localStorage.setItem(
"nomeProfessor",
document.getElementById("nomeProfessor").value
);
salvarLinksRespostas();
const editorContent = document.getElementById("editor-texto-livre");
if (editorContent) {
localStorage.setItem("textoLivre", editorContent.innerHTML);
}
const statusElement = document.getElementById("status");
statusElement.textContent = "Configurações atualizadas com sucesso!";
statusElement.className = "status success";
statusElement.style.display = "block";
setTimeout(function () {
statusElement.style.display = "none";
}, 3000);
const docLink = document.getElementById("abrirDocumento");
if (docLink) {
docLink.href = `respostas/modelo.html?t=${Date.now()}`;
}
}
});
}
function imprimirPDF() {
const botaoImprimir = document.querySelector(".botao-imprimir");
if (botaoImprimir) {
botaoImprimir.style.display = "none";
}
window.print();
setTimeout(() => {
if (botaoImprimir) {
botaoImprimir.style.display = "block";
}
}, 1000);
}
document.addEventListener("DOMContentLoaded", function () {
const botaoImprimir = document.querySelector(".botao-imprimir");
if (botaoImprimir) {
botaoImprimir.addEventListener("click", imprimirPDF);
}
});
document.addEventListener("DOMContentLoaded", function () {
initModeloPage();
initConfigurarPage();
});
document.addEventListener("DOMContentLoaded", function () {
const logo = document.querySelector(".rotating-logo");
if (logo) {
let isSpinning = false;
function toggleSpin() {
if (!isSpinning) {
logo.classList.add("spinning");
isSpinning = true;
setTimeout(() => {
logo.classList.remove("spinning");
logo.classList.add("stopping");
isSpinning = false;
setTimeout(() => {
logo.classList.remove("stopping");
}, 1000);
}, 5000);
}
}
setInterval(toggleSpin, 10000);
toggleSpin();
}
});
function initCustomEditor() {
const editor = document.getElementById("editor-texto-livre");
if (!editor) return;
const savedContent = localStorage.getItem("textoLivre");
if (savedContent && savedContent.trim() !== "") {
editor.innerHTML = savedContent;
} else {
editor.innerHTML = "";
}
function updateButtonStates() {
const buttons = document.querySelectorAll(".toolbar-btn");
buttons.forEach((button) => {
const command = button.dataset.command;
if (["bold", "italic", "underline", "strikeThrough"].includes(command)) {
if (document.queryCommandState(command)) {
button.classList.add("active");
} else {
button.classList.remove("active");
}
}
});
const formatSelector = document.querySelector(".toolbar-select");
if (formatSelector) {
const currentFormat = document
.queryCommandValue("formatBlock")
.replace(/[<>]/g, "");
if (
currentFormat &&
Array.from(formatSelector.options).some(
(option) => option.value === currentFormat
)
) {
formatSelector.value = currentFormat;
} else {
formatSelector.value = "p"; // Default to paragraph
}
}
}
const buttons = document.querySelectorAll(".toolbar-btn");
buttons.forEach((button) => {
button.addEventListener("click", function () {
const command = this.dataset.command;
if (
command === "bold" ||
command === "italic" ||
command === "underline" ||
command === "strikeThrough" ||
command === "justifyLeft" ||
command === "justifyCenter" ||
command === "justifyRight" ||
command === "insertUnorderedList" ||
command === "insertOrderedList"
) {
document.execCommand(command, false, null);
updateButtonStates();
}
editor.focus();
});
});
const formatSelector = document.querySelector(".toolbar-select");
if (formatSelector) {
formatSelector.addEventListener("change", function () {
const command = this.dataset.command;
const value = this.value;
if (command === "formatBlock") {
document.execCommand(command, false, "<" + value + ">");
}
editor.focus();
});
}
editor.addEventListener("click", function () {
this.focus();
updateButtonStates();
});
editor.addEventListener("keyup", updateButtonStates);
editor.addEventListener("mouseup", updateButtonStates);
document.addEventListener("selectionchange", function () {
if (document.activeElement === editor) {
updateButtonStates();
}
});
function isEditorEmpty() {
const content = editor.innerHTML.trim();
return (
content === "" || content === "<br>" || content === "<div><br></div>"
);
}
function updatePlaceholder() {
if (isEditorEmpty()) {
editor.classList.add("empty");
} else {
editor.classList.remove("empty");
}
}
editor.addEventListener("focus", function () {
this.classList.add("focused");
updatePlaceholder();
});
editor.addEventListener("blur", function () {
this.classList.remove("focused");
if (isEditorEmpty()) {
this.innerHTML = "";
}
updatePlaceholder();
});
editor.addEventListener("input", updatePlaceholder);
setTimeout(function () {
updateButtonStates();
updatePlaceholder();
}, 100);
}