-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
115 lines (90 loc) · 2.83 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
const btnEncriptar = document.querySelector(".btn-encriptar");
const btnDesencriptar = document.querySelector(".btn-desencriptar");
const muñeco = document.querySelector(".muneco");
const mensajeEncriptado = document.querySelector(".mensaje-encriptado");
const encriptadoP = document.querySelector(".parrafo");
const resultado = document.querySelector(".texto-resultado");
const container = document.querySelector(".container");
const mensajeError = document.querySelector(".titulo-mensaje");
btnEncriptar.onclick = encriptar;
btnDesencriptar.onclick = desencriptar;
function encriptar(){
var textoEncriptado = recuperarTexto()
resultado.textContent = encriptarTexto(textoEncriptado);
mensajeError.style.display = 'none';
muñeco.style.display = 'none';
encriptadoP.style.display = 'none';
}
function desencriptar(){
var textoEncriptado = recuperarTexto()
resultado.textContent = desencriptarTexto(textoEncriptado);
}
function recuperarTexto(){
var textoEncriptado = document.querySelector(".text-area")
return textoEncriptado.value
}
function ocultarAdelante(){
muñeco.classList.add("ocultar");
container.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] == "ai"){
textoFinal = textoFinal + "a"
i = i+1;
}
else if(texto[i] == "enter"){
textoFinal = textoFinal + "e"
i = i+4;
}
else if(texto[i] == "imes"){
textoFinal = textoFinal + "i"
i = i+3;
}
else if(texto[i] == "ober"){
textoFinal = textoFinal + "o"
i = i+3;
}
else if(texto[i] == "ufat"){
textoFinal = textoFinal + "u"
i = i+3;
}
else{
textoFinal = textoFinal + texto[i];
}
}
return textoFinal;
}
const btnCopiar = document.querySelector(".btnCopiar");
btnCopiar.addEventListener("click",() => {
var contenido = document.querySelector(".titulo-mensaje").textContent;
navigator.clipboard.writeText(contenido);
console.log("hola");
});