forked from Ihtram-Magno/encriptador.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript2.js
151 lines (121 loc) · 3.86 KB
/
script2.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*BOTONES Y AREAS DE TEXTO*/
let ingresarTexto = document.getElementById("ingTextAqui");
let salidaTexto = document.getElementById("msg");
let btnEncriptar = document.getElementById("btnEncriptar");
let btnDesencriptar = document.getElementById("btnDesencriptar");
let btnCopy = document.getElementById("btnCopy");
let btnReparar = document.querySelector("#reparar");
let borrar = document.getElementById("borrar");
let label = document.querySelector("label");
let imagen = document.getElementById("imagen");
ingresarTexto.focus();
const removeAccents = (str) => {
return str.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
}
// COMPORTAMIENTO DE LA PAGINA
function estadoNormal(){
label.style.border = " 2px solid #444";
label.style.color = "#fc0";
ingresarTexto.style.color = "#0f0";
ingresarTexto.style.border = "2px solid #0f0";
btnReparar.style.visibility = "hidden";
proceder = true
}
function estadoError(){
label.style.color = "#f00";
label.style.border = " 2px solid #f00";
ingresarTexto.style.color = "#f00";
ingresarTexto.style.border = "2px solid #fc0";
btnReparar.style.visibility = "visible";
proceder = false
}
/*DESAPARECER IMAGEN*/
function ocultarImagen() {
imagen.style.visibility = "hidden";
}
/*MOSTRAR IMAGEN*/
function mostrarImagen() {
imagen.style.visibility = "visible";
}
/*REPARAR TEXTO*/
btnReparar.addEventListener("click",reparar);
function reparar(){
let textoAreparar = removeAccents(ingresarTexto.value);
textoAreparar = textoAreparar.toLowerCase();
ingresarTexto.value = textoAreparar;
estadoNormal();
ingresarTexto.focus();
}
/*FUNCION PARA COMPROBAR ACENTOS Y MINUSCULAS*/
btnDesencriptar.addEventListener("click",desencriptar);
btnEncriptar.addEventListener("click",encriptar);
ingresarTexto.addEventListener("keyup",corregir);
let proceder = true;
function corregir(){
let requisitos = ingresarTexto.value;
let cumplir = removeAccents(ingresarTexto.value);
let cumplir2 = ingresarTexto.value.toLowerCase();
if(requisitos != cumplir){
estadoError();
}
if(requisitos != cumplir2){
estadoError();
}
if(requisitos == cumplir2 && requisitos == cumplir){
estadoNormal();
}
}
/*FUNCION DE ENCRIPTAR*/
function encriptar(){
if(proceder){
let texto = ingresarTexto.value
texto = texto.replaceAll("e", "enter");
texto = texto.replaceAll("i", "imes");
texto = texto.replaceAll("a", "ai");
texto = texto.replaceAll("o", "ober");
texto = texto.replaceAll("u", "ufat");
msg.value = texto;
if(ingresarTexto.value != ""){
ocultarImagen();
}
if(ingresarTexto.value == ""){
mostrarImagen();
}
}
}
/*DESENCRIPTAR*/
function desencriptar(){
if(proceder){
let texto = ingresarTexto.value
texto = texto.replaceAll("enter", "e");
texto = texto.replaceAll("imes", "i");
texto = texto.replaceAll("ai", "a");
texto = texto.replaceAll("ober", "o");
texto = texto.replaceAll("ufat", "u");
msg.value = texto;
if(ingresarTexto.value != ""){
ocultarImagen();
}
if(ingresarTexto.value == ""){
mostrarImagen();
}
}
}
/*FUNCION PARA COPIAR TEXTO*/
btnCopy.addEventListener("click", copiar);
function copiar(){
if(msg.value != ""){
ingresarTexto.value= msg.value;
navigator.clipboard.writeText(msg.value);
estadoNormal();
ingresarTexto.select();
}
ingresarTexto.focus();
}
//BOTON DE BORRAR
borrar.addEventListener("click",borrarTexto);
function borrarTexto(){
ingresarTexto.value = ""
ingresarTexto.focus();
estadoNormal();
}