-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscritp.js
105 lines (91 loc) · 2.99 KB
/
scritp.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
document.addEventListener("DOMContentLoaded", function () {
const buttonEncrip = document.getElementById("btnEncriptar");
const buttonDesencrip = document.getElementById("btnDesencriptar");
const buttonCopy = document.getElementById("buttonCopy");
const textInput = document.getElementById("textInput");
const textInputProcess = document.getElementById("textOutput");
// Función para encriptar el texto
function btnEncriptar() {
let input = textInput.value.toLowerCase();
const matrizCodigo = [
["e", "enter"],
["i", "imes"],
["a", "ai"],
["o", "ober"],
["u", "ufat"],
];
for (let i = 0; i < matrizCodigo.length; ++i) {
if (input.includes(matrizCodigo[i][0])) {
input = input.replaceAll(matrizCodigo[i][0], matrizCodigo[i][1]);
}
}
textInputProcess.value = input;
textInputProcess.style.background = "white";
textInputProcess.click();
window.getSelection().removeAllRanges();
}
// Función para desencriptar el texto
function btnDesencriptar() {
let output = textInput.value.toLowerCase();
const matrizCodigo = [
["e", "enter"],
["i", "imes"],
["a", "ai"],
["o", "ober"],
["u", "ufat"],
];
for (let i = 0; i < matrizCodigo.length; ++i) {
if (output.includes(matrizCodigo[i][0])) {
output = output.replaceAll(matrizCodigo[i][1], matrizCodigo[i][0]);
}
}
textInputProcess.value = output;
textInputProcess.style.background = "white";
textInputProcess.click();
}
// Función para copiar el resultado
function copy() {
const aux = document.createElement("input");
aux.setAttribute("value", textInputProcess.value);
document.body.appendChild(aux);
aux.select();
document.execCommand("copy");
document.body.removeChild(aux);
showAlert();
}
// Event listeners
buttonEncrip.onclick = btnEncriptar;
buttonDesencrip.onclick = btnDesencriptar;
buttonCopy.onclick = copy;
// Alerta
function showAlert() {
swal("Copiado", "El mensaje se ha copiado", "success");
}
// Mostrar y ocultar elementos
const textProcess = document.getElementById("outputContainer");
const imagen = document.getElementById("image");
textProcess.addEventListener("mouseover", () => {
if (textInputProcess.value === "") {
textInputProcess.value = "";
}
textInputProcess.style.display = "inline";
imagen.style.display = "none";
buttonCopy.style.display = "inline";
});
textProcess.addEventListener("mouseleave", () => {
if (textInputProcess.value === "") {
textInputProcess.value = "";
imagen.style.display = "inline";
textInputProcess.style.display = "none";
buttonCopy.style.display = "none";
}
});
textProcess.addEventListener("click", () => {
if (textInputProcess.value.length === 0) {
textInputProcess.value = "";
}
textInputProcess.style.display = "inline";
imagen.style.display = "none";
buttonCopy.style.display = "inline";
});
});