-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
133 lines (77 loc) · 2.82 KB
/
app.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
/*VARIABLES */
const textarea = document.querySelector('.textarea');
const btnEncriptar = document.querySelector('#encriptar');
const btnDesencriptar = document.querySelector('#desencriptar');
const mostrarResultado = document.querySelector('#mensaje');
const btnCopiar = document.querySelector('#copiar');
/**EVENTOS */
btnEncriptar.addEventListener('click', encriptar);
btnDesencriptar.addEventListener('click', desEncriptar);
btnCopiar.addEventListener('click', copiarTexto);
let textoEncriptado;
function encriptar() {
let textoIngresado = textarea.value;
if (textoIngresado.length > 0) {
textoEncriptado = textoIngresado;
if (textoEncriptado.includes('a')) {
textoEncriptado = textoEncriptado.replaceAll('a', 'ai');
}
if (textoEncriptado.includes('e')) {
textoEncriptado = textoEncriptado.replaceAll('e', 'enter');
}
if (textoEncriptado.includes('ai')) {
textoEncriptado = textoEncriptado;
} else {
textoEncriptado = textoEncriptado.replaceAll('i', 'imes');
}
if (textoEncriptado.includes('o')) {
textoEncriptado = textoEncriptado.replaceAll('o', 'ober');
}
if (textoEncriptado.includes('u')) {
textoEncriptado = textoEncriptado.replaceAll('u', 'ufat');
}
}
return mostrarMensaje(textoEncriptado);
}
function desEncriptar() {
let textoIngresado = textarea.value;
if (textoIngresado.length > 0) {
textoEncriptado = textoIngresado;
if (textoEncriptado.includes('ai')) {
textoEncriptado = textoEncriptado.replaceAll('ai', 'a');
}
if (textoEncriptado.includes('enter')) {
textoEncriptado = textoEncriptado.replaceAll('enter', 'e');
}
if (textoEncriptado.includes('imes')) {
textoEncriptado = textoEncriptado.replaceAll('imes', 'i');
}
if (textoEncriptado.includes('ober')) {
textoEncriptado = textoEncriptado.replaceAll('ober', 'o');
}
if (textoEncriptado.includes('ufat')) {
textoEncriptado = textoEncriptado.replaceAll('ufat', 'u');
}
}
return mostrarMensaje(textoEncriptado);
}
function mostrarMensaje(texto) {
if (textarea.value != '') {
btnCopiar.classList.remove('no-visible');
}
mostrarResultado.classList.add('mensaje-sin-img');
mostrarResultado.textContent = texto;
}
function copiarTexto() {
const copiado = document.querySelector('.copiado');
try {
navigator.clipboard.writeText(mostrarResultado.value);
copiado.textContent = '¡Copiado!';
btnCopiar.classList.add('no-visible');
setTimeout(() => {
copiado.remove();
}, 3000);
} catch (error) {
console.log(error);
}
}