-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
90 lines (78 loc) · 2.88 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
var botonEncriptar = document.querySelector(".btn-encriptar");
var botonDesencriptar = document.querySelector(".btn-desencriptar");
var munheco = document.querySelector(".contenedor-munheco");
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);
}
function desencriptar() {
ocultarAdelante();
var cajatexto = recuperarTexto();
resultado.textContent = desencriptarTexto(cajatexto);
}
function recuperarTexto() {
var cajatexto = document.querySelector(".cajatexto");
return cajatexto.value;
}
function ocultarAdelante() {
munheco.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[1] == "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 = "";
var i = 0;
while (i < texto.length) {
if (texto[i] == "a" && texto[i + 1] == "i") {
textoFinal = textoFinal + "a";
i = i + 2;
} else if (texto[i] == "e" && texto[i + 1] == "n" && texto[i + 2] == "t" && texto[i + 3] == "e" && texto[i + 4] == "r") {
textoFinal = textoFinal + "e";
i = i + 5;
} else if (texto[i] == "i" && texto[i + 1] == "m" && texto[i + 2] == "e" && texto[i + 3] == "s") {
textoFinal = textoFinal + "i";
i = i + 4;
} else if (texto[i] == "o" && texto[i + 1] == "b" && texto[i + 2] == "e" && texto[i + 3] == "r") {
textoFinal = textoFinal + "o";
i = i + 4;
} else if (texto[i] == "u" && texto[i + 1] == "f" && texto[i + 2] == "a" && texto[i + 3] == "t") {
textoFinal = textoFinal + "u";
i = i + 4;
} else {
textoFinal = textoFinal + texto[i];
i++;
}
}
return textoFinal;
}
const btnCopiar = document.querySelector(".btn-copiar");
btnCopiar.addEventListener("click", copiar = () => {
var contenido = document.querySelector(".contenedor-resultado .texto-resultado").textContent;
navigator.clipboard.writeText(contenido);
console.log(contenido);
});