-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
98 lines (88 loc) · 2.68 KB
/
script.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
var botonEncriptar = document.querySelector('.boton-encriptar');
var botonDesencriptar = document.querySelector('.boton-desencriptar');
var figura = document.querySelector('.contenedor-figura');
var contenedor = document.querySelector('.contenedor-parrafo');
var resultado = document.querySelector('.texto-resultado');
botonEncriptar.onclick = encriptar;
botonDesencriptar.onclick = desencriptar;
function encriptar(){
ocultarAdelante();
var cajatexto = recuperarTexto();
resultado.textContent = encriptarTexto(cajatexto);
// Vaciar el área de texto después de encriptar
document.querySelector('.caja-texto').value = '';
}
function desencriptar(){
ocultarAdelante();
var cajatexto = recuperarTexto();
resultado.textContent = desencriptarTexto(cajatexto);
}
function recuperarTexto(){
var cajatexto = document.querySelector('.caja-texto')
return cajatexto.value
}
function ocultarAdelante(){
contenedor-figura.classList.add('ocultar');
contenedor.classList.add('ocultar');
}
function encriptarTexto(mensaje){
var texto = mensaje;
var textoFinal = '';
for (var i = 0; i < texto.length; i++){
if(texto[i] == 'a'){
textoFinal = textoFinal + 'ai'
}
else if(texto[i] == 'e'){
textoFinal = textoFinal + 'enter'
}
else if(texto[i] == 'i'){
textoFinal = textoFinal + 'imes'
}
else if(texto[i] == 'o'){
textoFinal = textoFinal + 'ober'
}
else if(texto[i] == 'u'){
textoFinal = textoFinal + 'ufat'
}
else{
textoFinal = textoFinal + texto[i]
}
}
return textoFinal;
}
function desencriptarTexto(mensaje){
var texto = mensaje;
var textoFinal = '';
for (var i = 0; i < texto.length; i++){
if(texto[i] == 'a'){
textoFinal = textoFinal + 'a'
i = i+1;
}
else if(texto[i] == 'e'){
textoFinal = textoFinal + 'e'
i = i+4;
}
else if(texto[i] == 'i'){
textoFinal = textoFinal + 'i'
i = i+3;
}
else if(texto[i] == 'o'){
textoFinal = textoFinal + 'o'
i = i+3;
}
else if(texto[i] == 'u'){
textoFinal = textoFinal + 'u'
i = i+3;
}
else{
textoFinal = textoFinal + texto[i]
}
}
return textoFinal;
}
const botonCopiar = document.querySelector('.boton-copiar');
botonCopiar.addEventListener('click',copiar = () => {
var contenido = document.querySelector('.texto-resultado').textContent;
navigator.clipboard.writeText(contenido)
console.log('Hola');
})