-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle.js
71 lines (54 loc) · 1.86 KB
/
style.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
const botonEncriptar = document.querySelector("#btonEncriptar");
const botonDesencriptar = document.querySelector("#btonDesencriptar");
const botonCopiar = document.querySelector("#btonCopiar");
const textoUsuario = document.querySelector("#textoUsuario");
const mostrarTexto = document.querySelector("#texto-resultado");
const ventanaInicio = document.querySelector("#imagenInicio");
const ventanaResultado = document.querySelector("#contenedorTexto");
let textoFinal;
const llaves = {
e: "enter",
i: "imes",
a: "ai",
o: "ober",
u: "ufat",
};
function encriptar() {
const textoIngresado = textoUsuario.value.toLowerCase();
textoFinal = textoIngresado;
if (textoIngresado.trim() != "") {
for (const propiedad in llaves) {
textoFinal = textoFinal.replaceAll(propiedad, llaves[propiedad]);
}
mostrarVentana();
} else {
alert("Error! Ingrese el texto a encriptar..");
}
}
function desencriptar() {
textoFinal = textoUsuario.value.toLowerCase();
if (textoUsuario.value.trim() != "") {
for (const propiedad in llaves) {
textoFinal = textoFinal.replaceAll(llaves[propiedad], propiedad);
}
mostrarVentana();
} else {
alert("Error! por favor ingrese el texto a desencriptar..");
}
}
function mostrarVentana() {
ventanaInicio.style.display = "none";
ventanaResultado.style.display = "flex";
mostrarTexto.innerHTML = textoFinal;
textoUsuario.value = "";
}
function copiarTexto() {
const text = mostrarTexto.textContent;
navigator.clipboard
.writeText(text)
.then(() => console.log("Copiado con exito!"))
.catch((err) => console.log("Error al copiar el texto."));
}
botonEncriptar.addEventListener("click", encriptar);
botonDesencriptar.addEventListener("click", desencriptar);
botonCopiar.addEventListener("click", copiarTexto);