-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
73 lines (63 loc) · 2.46 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
var emails = [];
function realizarSorteio() {
var emailList = document.getElementById("emailList").value;
var fileInput = document.getElementById("fileInput");
if (emailList.trim() !== "") {
emails = emailList.split("\n");
} else if (fileInput.files.length > 0) {
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var data = new Uint8Array(e.target.result);
var workbook = XLSX.read(data, { type: "array" });
var worksheet = workbook.Sheets[workbook.SheetNames[0]];
var jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
emails = jsonData.flat().filter((email) => email !== "");
};
reader.readAsArrayBuffer(file);
} else {
emails = [];
}
var numeroParticipantes = emails.length;
if (numeroParticipantes > 0) {
var indiceVencedor = Math.floor(Math.random() * numeroParticipantes);
var emailVencedor = emails[indiceVencedor].trim();
if (emailVencedor !== "") {
document.getElementById("vencedor").textContent = emailVencedor;
abrirModal(emailVencedor);
criarConfetes();
} else {
realizarSorteio(); // Realiza o sorteio novamente se o ganhador for um espaço em branco
}
} else {
document.getElementById("vencedor").textContent = "Nenhum email inserido.";
}
}
function abrirModal(vencedor) {
var modal = document.getElementById("modal");
var modalWinner = document.getElementById("modalWinner");
modalWinner.textContent = vencedor;
modal.style.display = "block";
}
function fecharModal() {
var modal = document.getElementById("modal");
modal.style.display = "none";
removerConfetes();
}
function criarConfetes() {
var container = document.querySelector(".container");
for (var i = 0; i < 100; i++) {
var confetti = document.createElement("div");
confetti.classList.add("confetti");
confetti.style.left = Math.random() * 100 + "%";
confetti.style.animationDelay = Math.random() + "s";
container.appendChild(confetti);
}
}
function removerConfetes() {
var confettis = document.querySelectorAll(".confetti");
for (var i = 0; i < confettis.length; i++) {
var confetti = confettis[i];
confetti.parentNode.removeChild(confetti);
}
}