-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncriptador.js
115 lines (95 loc) · 3.6 KB
/
Encriptador.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
111
112
113
114
const btnEncriptar = document.querySelector(".btn-encriptar");
const txtEncriptar = document.querySelector(".encriptar");
const aviso = document.querySelector(".textalert");
const respuesta = document.querySelector(".evaluar");
const contenido = document.querySelector(".tarjeta-visualizador");
const btnCopiar = document.querySelector(".btn-copiar");
const btnDesencriptar = document.querySelector(".btn-desencriptar");
btnEncriptar.addEventListener("click", e=>{
e.preventDefault();
let texto = txtEncriptar.value;
let txt = texto.normalize("NFD").replace(/[$\.¿\?~!\¡@#%^&*()_|}\{[\]>\<:"`;,\u0300-\u036f']/g, "");
if(texto == ""){
aviso.style.background = "#0A3871";
aviso.style.color = "#FFFF";
aviso.style.fontWeight = "800";
aviso.textContent = "El campo de texto está vacio";
setTimeout(()=>{
aviso.removeAttribute("style");
},1500);
}
else if(texto !== txt){
aviso.style.background = "#0A3871";
aviso.style.color = "#FFFF";
aviso.style.fontWeight = "800";
aviso.textContent = "No usar caracteres especiales";
setTimeout(()=>{
aviso.removeAttribute("style");
},1500);
}
else if(texto !== texto.toLowerCase()){
aviso.style.background = "#0A3871";
aviso.style.color = "#FFFF";
aviso.style.fontWeight = "800";
aviso.textContent = "Solo letras minúsculas y sin acentos";
setTimeout(()=>{
aviso.removeAttribute("style");
},1500);
}
else{
texto = texto.replace(/e/mg, "enter");
texto = texto.replace(/i/mg, "imes");
texto = texto.replace(/a/mg, "ai");
texto = texto.replace(/o/mg, "ober");
texto = texto.replace(/u/mg, "ufat");
respuesta.innerHTML = texto;
btnCopiar.style.visibility = "inherit";
contenido.remove();
}
});
btnDesencriptar.addEventListener("click", e=>{
e.preventDefault();
let texto = txtEncriptar.value;
let txt = texto.normalize("NFD").replace(/[$\.¿\?~!\¡@#%^&*()_|}\{[\]>\<:"`;,\u0300-\u036f']/g, "");
if(texto == ""){
aviso.style.background = "#0A3871";
aviso.style.color = "#FFFF";
aviso.style.fontWeight = "800";
aviso.textContent = "El campo de texto no debe estar vacio";
setTimeout(()=>{
aviso.removeAttribute("style");
},1500);
}
else if(texto !== txt){
aviso.style.background = "#0A3871";
aviso.style.color = "#FFFF";
aviso.style.fontWeight = "800";
aviso.textContent = "No debe tener acentos y caracteres especiales";
setTimeout(()=>{
aviso.removeAttribute("style");
},1500);
}
else if(texto !== texto.toLowerCase()){
aviso.style.background = "#0A3871";
aviso.style.color = "#FFFF";
aviso.style.fontWeight = "800";
aviso.textContent = "El texto debe ser todo en minúscula";
setTimeout(()=>{
aviso.removeAttribute("style");
},1500);
}
else{
texto = texto.replace(/enter/mg, "e");
texto = texto.replace(/imes/mg, "i");
texto = texto.replace(/ai/mg, "a");
texto = texto.replace(/ober/mg, "o");
texto = texto.replace(/ufat/mg, "u");
respuesta.innerHTML = texto;
btnCopiar.style.visibility = "inherit";
contenido.remove();
}
});
btnCopiar.addEventListener("click", copiar = () => {
var contenido = document.querySelector(".evaluar").textContent;
navigator.clipboard.writeText(contenido);
})