-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
99 lines (82 loc) · 2.99 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
// Función de encriptar //
function encrypt() {
var textInput = document.querySelector("#userText").value;
var textEncrypt = textInput.replace(/[aeiou]/gi, function(match) {
switch (match.toLowerCase()) {
case 'a':
return 'ai';
case 'e':
return 'enter';
case 'i':
return 'imes';
case 'o':
return 'ober';
case 'u':
return 'ufat';
default:
return match;
}
});
document.querySelector(".text-result").value = textEncrypt;
}
var btnEncrypt = document.querySelector("#btn-encrypt");
btnEncrypt.addEventListener("click", encrypt);
// Función de desencriptar //
function decrypt() {
var textInput = document.querySelector("#userText").value;
var textDecrypt = textInput.replace(/ai|enter|imes|ober|ufat/gi, function(match) {
switch (match.toLowerCase()) {
case 'ai':
return 'a';
case 'enter':
return 'e';
case 'imes':
return 'i';
case 'ober':
return 'o';
case 'ufat':
return 'u';
default:
return match;
}
});
document.querySelector(".text-result").value = textDecrypt;
}
var btnDecrypt = document.querySelector("#btn-decrypt");
btnDecrypt.addEventListener("click", decrypt);
// función que oculta el main results y muestra el textarea con el texto encriptado o desencriptado y los botones de copiar y pegar//
var textResult = document.querySelector("#textResult");
var copyFun = document.querySelector("#btn-copy");
var pasteFun = document.querySelector("#btn-paste");
textResult.style.display = "none";
copyFun.style.display = "none";
pasteFun.style.display= "none";
function showResults() {
textResult.style.display = "block";
copyFun.style.display = "block";
}
function showBtnPaste() {
pasteFun.style.display= "block";
}
var btnEncrypt = document.querySelector("#btn-encrypt");
btnEncrypt.addEventListener("click", showResults);
var btnCopy = document.querySelector("#btn-copy");
btnCopy.addEventListener("click", showBtnPaste);
// Función del botón para copiar
function copyText() {
var textInputCopy = document.querySelector("#textResult").value;
navigator.clipboard.writeText(textInputCopy);
}
var btnCopy = document.querySelector("#btn-copy");
btnCopy.addEventListener("click", copyText);
// Función de pegar
function pasteText() {
navigator.clipboard.readText().then(function(textInputPaste) {
var userTextArea = document.querySelector("#userText");
userTextArea.value = textInputPaste;
}).catch(function(error) {
console.error("Error al pegar el texto:", error);
});
}
var btnPaste = document.querySelector("#btn-paste");
btnPaste.addEventListener("click", pasteText);