Repository navigation
Expand file tree
/
Copy pathscript2.js
More file actions
152 lines (120 loc) · 3.79 KB
/
Copy pathscript2.js
File metadata and controls
152 lines (120 loc) · 3.79 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
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
152
/*BOTONES Y AREAS DE TEXTO*/
const ingresarTexto = document.getElementById("ingTextAqui");
const salidaTexto = document.getElementById("msg");
const btnEncriptar = document.getElementById("btnEncriptar");
const btnDesencriptar = document.getElementById("btnDesencriptar");
const btnCopy = document.getElementById("btnCopy");
const btnReparar = document.querySelector("#reparar");
const borrar = document.getElementById("borrar");
const label = document.querySelector("label");
const 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();
}
}
// diccionario
const vocal = ["e", "i", "a", "o", "u"];
const vocalEncriptada = ["enter", "imes", "ai", "ober", "uber"];
/*FUNCION DE ENCRIPTAR*/
function encriptar(){
if(proceder){
let texto = ingresarTexto.value
for (let i = 0; i < vocal.length; i++) {
texto = texto.replaceAll(vocal[i], vocalEncriptada[i]);
}
msg.value = texto;
if(ingresarTexto.value != ""){
ocultarImagen();
}
if(ingresarTexto.value == ""){
mostrarImagen();
}
}
}
/*DESENCRIPTAR*/
function desencriptar(){
if(proceder){
let texto = ingresarTexto.value
for (let i = 0; i < vocal.length; i++) {
texto = texto.replaceAll(vocalEncriptada[i], vocal[i]);
}
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();
}