-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
111 lines (96 loc) · 2.55 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
99
100
101
102
103
104
105
106
107
108
109
110
111
var btnEncriptar = document.querySelector(".btnEncriptar");
var btnDesencriptar = document.querySelector(".btnDesencriptar");
var btnCopiar = document.querySelector(".btnCopiar");
var imgMuneco = document.querySelector(".cajaMuneco");
var cajaEncriptado = document.querySelector(".cajaMensaje");
var txtResultado = document.querySelector(".txtResultado");
btnCopiar.hidden=true;
btnEncriptar.onclick = fnEcriptar;
btnDesencriptar.onclick = fnDesencriptar;
btnCopiar.onclick = fnCopiarTxt;
function fnEcriptar(){
fnEsconder();
fnMostrarBtnCopiar();
var txtUsuario = fnObtenerTxt();
txtResultado.textContent = fnEncriptarTxt(txtUsuario);
}
function fnDesencriptar(){
fnEsconder();
fnMostrarBtnCopiar();
var txtUsuarioDes = fnObtenerTxt();
txtResultado.textContent = fnDesencriptarTxt(txtUsuarioDes);
console.log(txtUsuarioDes);
}
function fnEsconder(){
imgMuneco.classList.add("Esconder");
cajaEncriptado.classList.add("Esconder");
}
function fnMostrarBtnCopiar(){
btnCopiar.hidden = false;
}
function fnEncriptarTxt(mensaje){
var txt = mensaje;
var txtFinal = "";
for(var i=0;i<txt.length;i++){
if(txt[i] =='a'){
txtFinal = txtFinal + "ai";
}
else if(txt[i] == 'e'){
txtFinal = txtFinal + "enter";
}
else if(txt[i] == 'i'){
txtFinal = txtFinal + "imes";
}
else if(txt[i] == 'o'){
txtFinal = txtFinal + "ober";
}
else if(txt[i] == 'u'){
txtFinal = txtFinal + "ufat";
}
else{
txtFinal = txtFinal + txt[i];
}
}
return txtFinal;
}
function fnDesencriptarTxt(mensaje){
var txt = mensaje;
var txtFinal = "";
for(var i=0;i<txt.length;i++){
if(txt[i] == "a"){
txtFinal = txtFinal + "a";
i = i + 1;
}
else if(txt[i] == "e"){
txtFinal = txtFinal + "e";
i = i + 4;
}
else if(txt[i] == "i"){
txtFinal = txtFinal + "i";
i = i + 3;
}
else if(txt[i] == "o"){
txtFinal = txtFinal + "o";
i = i + 3;
}
else if(txt[i] == "u"){
txtFinal = txtFinal + "u";
i = i + 3;
}
else{
txtFinal = txtFinal + txt[i];
}
}
return txtFinal;
}
function fnObtenerTxt(){
var texto = document.querySelector(".textoOrigen");
return texto.value;
}
function fnCopiarTxt(){
btnCopiar.addEventListener("click", copiar = () =>{
var txtCopiar = document.querySelector(".txtResultado").textContent;
navigator.clipboard.writeText(txtCopiar);
console.log(txtCopiar);
})
}