-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
110 lines (103 loc) · 3.64 KB
/
utils.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
function caos() {
return {
seconds: "00",
minutes: "00",
hours: "00",
days: "00",
distance: 0,
countdown: null,
beerTime: new Date("Jan 31, 2024 00:00:00").getTime(),
now: new Date().getTime(),
start: function () {
this.countdown = setInterval(() => {
// Calculate time
this.now = new Date().getTime();
this.distance = this.beerTime - this.now;
// Set Times
this.days = this.padNum(
Math.floor(this.distance / (1000 * 60 * 60 * 24))
);
this.hours = this.padNum(
Math.floor((this.distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
);
this.minutes = this.padNum(
Math.floor((this.distance % (1000 * 60 * 60)) / (1000 * 60))
);
this.seconds = this.padNum(
Math.floor((this.distance % (1000 * 60)) / 1000)
);
// Stop
if (this.distance < 0) {
clearInterval(this.countdown);
this.days = "00";
this.hours = "00";
this.minutes = "00";
this.seconds = "00";
}
}, 100);
},
padNum: function (num) {
var zero = "";
for (var i = 0; i < 2; i++) {
zero += "0";
}
return (zero + num).slice(-2);
},
};
}
document.addEventListener("DOMContentLoaded", function () {
const urlParams = new URLSearchParams(window.location.search);
const vemcausar = urlParams.get("vemcausar");
const form = document.getElementById("myForm");
if (form) {
form.addEventListener("submit", function (e) {
e.preventDefault();
const email = document.getElementById("email").value;
var dataAtual = new Date();
var dataCadastro = JSON.stringify(dataAtual);
const formData = {
form: {
usuário: {
dataCadastro: dataCadastro,
id: email,
nome: document.getElementById("nome").value,
email: document.getElementById("email").value,
telefone: document.getElementById("telefone").value,
indicacao: vemcausar, // Adiciona o email do indicador se existir
},
},
};
fetch("https://caos.tgbprog.workers.dev/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(formData),
})
.then((data) => {
// Gera a URL de indicação com o e-mail do usuário atual codificado
document.getElementById("myForm").style.display = "none";
const responseDiv = document.getElementById("response");
responseDiv.style.display = "block";
// Atualiza o link para copiar e a mensagem de sucesso
const refLink = `https://caos.wtf/?vemcausar=${btoa(email)}`;
let responseText = `Dados enviados com sucesso! <br>Compartilhe o Caos!`;
responseDiv.innerHTML = `
<span>${responseText}</span>
<div class="mt-4 flex flex-col justify-between items-center">
<span id="linkToCopy" class="text-green-500 hover:text-green-700 cursor-pointer">${refLink}</span>
<button onclick="copyLink()" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded">Copiar</button>
</div>
`; // Inclui a mensagem de sucesso e o novo link
})
.catch((error) => {
console.error("Error:", error);
});
});
}
});
function copyLink() {
var link = document.getElementById("linkToCopy").innerText;
navigator.clipboard.writeText(link);
// Adicionar feedback de link copiado, se desejado
}