-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReturnKey.js
More file actions
89 lines (78 loc) · 2.54 KB
/
Copy pathReturnKey.js
File metadata and controls
89 lines (78 loc) · 2.54 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
const KeyDisplay = document.getElementById('chave')
const CopyKeyButton = document.getElementById('copyBtn')
const title = document.getElementById('CardTitle')
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString)
const urlToken = urlParams.get('token')
const tokenValido = false
GetToken(urlToken);
async function GetToken(token)
{
if (!token)
{
KeyDisplay.innerText = 'Não foi possivel gerar a chave. (token not found)'
KeyDisplay.style.color = 'rgb(210,43,37)'
CopyKeyButton.disabled = true
CopyKeyButton.style.pointerEvents = 'none'
CopyKeyButton.style.filter = 'brightness(40%)'
title.style.color = 'rgb(210,43,37)'
title.style.fontWeight = 'bold'
sconderLoader();
}
else
{
const key = await VerifyToken(token)
if (key !== false)
{
KeyDisplay.innerText = key
KeyDisplay.style.color = 'rgb(0,255,0)'
title.style.color = 'rgb(0,255,0)'
CopyKeyButton.style.filter = 'brightness(120%)'
title.style.fontWeight = 'bold'
title.innerText = 'Chave Gerada'
esconderLoader();
}
else
{
KeyDisplay.innerText = 'Não foi possivel gerar a chave. (invalid token)'
KeyDisplay.style.color = 'rgb(210,43,37)'
CopyKeyButton.disabled = true
CopyKeyButton.style.pointerEvents = 'none'
CopyKeyButton.style.filter = 'brightness(40%)'
title.style.color = 'rgb(210,43,37)'
title.style.fontWeight = 'bold'
title.innerText = 'Token Invalido'
sconderLoader();
}
}
}
async function VerifyToken(token) {
try
{
const response = await fetch('https://returnkey.greenscriptshub.workers.dev', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token })
})
if (!response.ok) {
const errorData = await response.json();
console.error('Detalhe do Erro no Banco:', errorData);
esconderLoader();
return false
}
const data = await response.json()
return data.key
} catch (error)
{
window.alert("Ocorreu um erro no nosso servidor, tente novamente mais tarde")
esconderLoader();
console.log(error)
return false
}
}
function esconderLoader() {
const loader = document.getElementById('loader');
loader.classList.add('loader-hide');
setTimeout(() => loader.remove(), 600);
}
setTimeout(esconderLoader, 7500);