-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
114 lines (96 loc) · 3.17 KB
/
index.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
// Seleccionar elementos del DOM
var botonEncriptar = document.querySelector(".Btn-Encriptar");
var botonDesencriptar = document.querySelector(".Btn-Desencriptar");
var imagen = document.querySelector(".Contenedor_Imagen");
var contenedor = document.querySelector(".Contenedor_Parrafo");
var resultado = document.querySelector(".Texto_Resultado");
// Asignar eventos a los botones
botonEncriptar.onclick = encriptar;
botonDesencriptar.onclick = desencriptar;
// Función para encriptar texto
function encriptar() {
ocultarContenedor();
var ContenedorTexto = recuperarTexto();
resultado.textContent = encriptarTexto(ContenedorTexto);
document.querySelector(".ContenedorTexto").value = ""; // Limpiar el área de texto
document.querySelector(".ContenedorTexto").setAttribute("placeholder", "Ingrese texto"); // Restaurar el placeholder
}
function desencriptar() {
ocultarContenedor();
var ContenedorTexto = recuperarTexto();
resultado.textContent = desencriptarTexto(ContenedorTexto);
document.querySelector(".ContenedorTexto").value = ""; // Limpiar el área de texto
document.querySelector(".ContenedorTexto").setAttribute("placeholder", "Ingrese texto"); // Restaurar el placeholder
}
function recuperarTexto() {
var ContenedorTexto = document.querySelector(".ContenedorTexto");
return ContenedorTexto.value;
}
function ocultarContenedor() {
imagen.classList.add("ocultar");
contenedor.classList.add("ocultar");
}
function encriptarTexto(mensaje) {
var textoFinal = "";
for (var i = 0; i < mensaje.length; i++) {
switch (mensaje[i]) {
case 'a':
textoFinal += 'ai';
break;
case 'e':
textoFinal += 'enter';
break;
case 'i':
textoFinal += 'imes';
break;
case 'o':
textoFinal += 'ober';
break;
case 'u':
textoFinal += 'ufat';
break;
default:
textoFinal += mensaje[i];
break;
}
}
return textoFinal;
}
// Función para desencriptar texto
function desencriptarTexto(mensaje) {
var textoFinal = "";
for (var i = 0; i < mensaje.length; i++) {
switch (mensaje.substring(i, i + 2)) {
case 'ai':
textoFinal += 'a';
i++;
break;
case 'en':
textoFinal += 'e';
i += 4;
break;
case 'im':
textoFinal += 'i';
i += 3;
break;
case 'ob':
textoFinal += 'o';
i += 3;
break;
case 'uf':
textoFinal += 'u';
i += 3;
break;
default:
textoFinal += mensaje[i];
break;
}
}
return textoFinal;
}
// Asignar evento al botón de copiar
const btnCopiar = document.querySelector(".Btn_Copiar");
btnCopiar.addEventListener("click", function() {
var contenido = resultado.textContent;
navigator.clipboard.writeText(contenido);
});