-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchivo.js
124 lines (99 loc) · 3.1 KB
/
archivo.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
115
116
var botonEncriptar = document.querySelector(".botonencriptar");
var botonDesencriptar = document.querySelector(".botondesencriptar");
var munieco = document.querySelector(".contenedor-imagen")
var h3 = document.querySelector(".contenedor-texto")
var parrafo = document.querySelector(".contenedor-parrafo")
var resultado = document.querySelector(".texto-resultado")
var botonCopiar = document.querySelector(".bcopiar")
botonEncriptar.onclick = encriptar;
botonDesencriptar.onclick = desencriptar;
botonCopiar.onclick = copiar;
function encriptar() {
var area = recuperarTexto ()
ocultarAdelante();
resultado.textContent = encriptarTexto(area);
document.getElementsByClassName("caja")[0].value = ""; /*borar caja */
}
function desencriptar() {
var area = recuperarTexto()
ocultarAdelante();
resultado.textContent = desencriptarTexto(area);
document.getElementsByClassName("caja")[0].value = ""; /*borar caja */
}
function recuperarTexto() {
var area = document.querySelector(".caja")
return area.value
}
function ocultarAdelante() {
munieco.classList.add("esconder");
h3.classList.add("esconder");
parrafo.classList.add("esconder");
}
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;
}
/* copiar resultado */
document.querySelector(".bcopiar").addEventListener("click", () => {
copiar(resultado)
})
function copiar(resultado) {
var textoOculto = document.createElement("input")
textoOculto.setAttribute("value", resultado.innerText);
document.body.appendChild(textoOculto);
textoOculto.select();
document.execCommand ("copy");
document.body.removeChild(textoOculto);
resultado.textContent = value ="" /*borar resultado o caja*/
}