-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
162 lines (143 loc) · 5.37 KB
/
main.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
152
153
154
155
156
157
158
159
160
161
162
/*Obteniendo el texto al dar click en el botón de encriptar*/
document.getElementById("encriptar").addEventListener("click", function () {
let textoIngresado = document.getElementById("textoIngresado").value.toLowerCase();
let textoEncriptado = encriptar(textoIngresado);
document.getElementById("textoProcesado").innerHTML = textoEncriptado;
/*Se remueve el contenido del div*/
let imagen = document.getElementById("ImgNoEncontrado");
let strong = document.getElementById("NoEncontrado");
let textoProcesado = document.getElementById("textoProcesado");
// Eliminar la imagen y la etiqueta
imagen.classList.remove("aparecer");
strong.classList.remove("aparecer");
imagen.classList.add("desaparecer");
strong.classList.add("desaparecer");
textoProcesado.style.height = "25em";
});
/*Se ingresa la cadena de texto y se toma cada posición para que en esta se pueda hacer la manipulación
en caso de ser una vocal.*/
function encriptar(textoIngresado) {
let contador = 0;
let longitud = textoIngresado.length;
let textoEncriptado = "";
while (contador < longitud) {
let letraActual = textoIngresado[contador];
if (letraActual === "a") {
textoEncriptado += "ai";
} else if (letraActual === "e") {
textoEncriptado += "enter";
} else if (letraActual === "i") {
textoEncriptado += "imes";
} else if (letraActual === "o") {
textoEncriptado += "ober";
} else if (letraActual === "u") {
textoEncriptado += "utaf";
} else {
textoEncriptado += letraActual;
}
contador++;
}
return textoEncriptado;
}
document.getElementById("desencriptar").addEventListener("click", function () {
let textoIngresado = document.getElementById("textoIngresado").value.toLowerCase();
let textoEncriptado = desencriptar(textoIngresado);
document.getElementById("textoProcesado").innerHTML = textoEncriptado;
/*Se remueve el contenido del div*/
let imagen = document.getElementById("ImgNoEncontrado");
let strong = document.getElementById("NoEncontrado");
let textoProcesado = document.getElementById("textoProcesado");
// Eliminar la imagen y la etiqueta
imagen.classList.remove("aparecer");
strong.classList.remove("aparecer");
imagen.classList.add("desaparecer");
strong.classList.add("desaparecer");
textoProcesado.style.height = "25em";
});
function desencriptar(textoEncriptado) {
let textoDesencriptado = "";
let i = 0;
while (i < textoEncriptado.length) {
if (textoEncriptado.slice(i, i + 2) === "ai") {
textoDesencriptado += "a";
i += 2;
} else if (textoEncriptado.slice(i, i + 5) === "enter") {
textoDesencriptado += "e";
i += 5;
} else if (textoEncriptado.slice(i, i + 4) === "imes") {
textoDesencriptado += "i";
i += 4;
} else if (textoEncriptado.slice(i, i + 4) === "ober") {
textoDesencriptado += "o";
i += 4;
} else if (textoEncriptado.slice(i, i + 4) === "utaf") {
textoDesencriptado += "u";
i += 4;
} else {
textoDesencriptado += textoEncriptado[i];
i += 1;
}
}
return textoDesencriptado;
}
let textoProcesado = document.getElementById("textoProcesado");
let btnCopiar = document.getElementById("btnCopiar");
btnCopiar.addEventListener("click", function () {
let texto = textoProcesado.textContent;
navigator.clipboard.writeText(texto)
/*.then se usa cuando se cumple una "promesa" e este caso se usa para imprimir un alert*/
.then(() => {
let mensaje = document.createElement("div");
mensaje.classList.add("mensaje")
mensaje.innerText = "¡Texto copiado con éxito!";
// Agregar el mensaje al div
document.body.appendChild(mensaje);
// Remover el div después de un intervalo de tiempo
setTimeout(function () {
mensaje.classList.add("mover");
}, 1750);
setTimeout(function () {
mensaje.remove();
}, 3000);
});
});
function desencriptar(textoEncriptado) {
let textoDesencriptado = "";
let i = 0;
while (i < textoEncriptado.length) {
if (textoEncriptado.slice(i, i + 2) === "ai") {
textoDesencriptado += "a";
i += 2;
} else if (textoEncriptado.slice(i, i + 5) === "enter") {
textoDesencriptado += "e";
i += 5;
} else if (textoEncriptado.slice(i, i + 4) === "imes") {
textoDesencriptado += "i";
i += 4;
} else if (textoEncriptado.slice(i, i + 4) === "ober") {
textoDesencriptado += "o";
i += 4;
} else if (textoEncriptado.slice(i, i + 4) === "utaf") {
textoDesencriptado += "u";
i += 4;
} else {
textoDesencriptado += textoEncriptado[i];
i += 1;
}
}
return textoDesencriptado;
}
document.getElementById("btnLimpiar").addEventListener("click", function () {
/*Elimina el contenido de los textos ingresados previamente.*/
document.getElementById("textoProcesado").innerHTML = "";
/*Se devuelve la imagen y el strong*/
/*Se remueve el contenido del div*/
let imagen = document.getElementById("ImgNoEncontrado");
let strong = document.getElementById("NoEncontrado");
let textoProcesado = document.getElementById("textoProcesado");
// Eliminar la imagen y la etiqueta
imagen.classList.add("aparecer");
strong.classList.add("aparecer");
textoProcesado.style.height = "initial";
textoProcesado.innerText = "Ingresa el texto que desees encriptar o desencriptar";
});