-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
84 lines (67 loc) · 3.03 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
73
74
75
76
77
78
79
80
81
82
83
84
document.addEventListener('DOMContentLoaded', function () {
var campoTexto = document.getElementById('areaTexto');
var btnCriptografar = document.getElementById('btnCriptografar');
var btnDescriptografar = document.getElementById('btnDescriptografar');
var textoDestino = document.getElementById('areaCopia');
var btnCopiar = document.getElementById('botaoCopiar');
var campoCopia = document.getElementById('areaCopia');
var conteudoAreaCopia = document.querySelector('.conteudo__area-de-copia');
var conteudoMensagens = document.querySelector('.conteudo__principal__mensagens');
var logoAlura = document.querySelector('.logo-alura');
// Recarregar a página ao clicar na logo
logoAlura.addEventListener('click', function () {
location.reload();
});
// Função que verifica se o campo de texto está vazio para não habilitar os botões sem necessidade
function verificarTexto() {
var textoNoCampo = campoTexto.value.trim();
btnCriptografar.disabled = textoNoCampo === '';
btnDescriptografar.disabled = textoNoCampo === '';
}
// Previne acentos e caracteres especiais no campo de texto
campoTexto.addEventListener('input', function () {
this.value = this.value.normalize('NFD').replace(/[\u0300-\u036f]/g, "");
this.value = this.value.replace(/[^\w\s]/gi, "");
verificarTexto();
});
btnCriptografar.addEventListener('click', function () {
if (!this.disabled) {
var textoCriptografado = campoTexto.value;
// Criptografa o texto
var textoModificado = textoCriptografado.replace(/e/g, "enter")
.replace(/i/g, "imes")
.replace(/a/g, "ai")
.replace(/o/g, "ober")
.replace(/u/g, "ufat");
textoDestino.textContent = textoModificado;
textoDestino.classList.add('ativo');
conteudoAreaCopia.style.display = 'block';
conteudoMensagens.style.display = 'none';
}
});
btnDescriptografar.addEventListener('click', function () {
if (!this.disabled) {
var textoDescriptografado = campoTexto.value;
// Descriptografa o texto
var textoModificado = textoDescriptografado.replace(/enter/g, "e")
.replace(/imes/g, "i")
.replace(/ai/g, "a")
.replace(/ober/g, "o")
.replace(/ufat/g, "u");
textoDestino.textContent = textoModificado;
textoDestino.classList.add('ativo');
conteudoAreaCopia.style.display = 'block';
conteudoMensagens.style.display = 'none';
}
});
// Botão de copiar o texto
btnCopiar.addEventListener('click', function () {
if (campoCopia.value.length > 0) {
campoCopia.select();
campoCopia.setSelectionRange(0, 99999);
document.execCommand('copy');
}
});
// Chama a função de verificação para configurar o estado dos botões
verificarTexto();
});