-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.js
122 lines (70 loc) · 2.9 KB
/
javascript.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
117
118
119
120
121
122
// ---------------Declaracion de variables------------- //
let textIn = document.getElementById( "text-in" );
let textOut = document.getElementById( "text-out" );
let btnEncrypt = document.getElementById( "btn-encrypt" );
let btnDecrypt = document.getElementById( "btn-decrypt" );
let btnCopiar = document.getElementById( "btn-copy" );
let btnClean = document.getElementById( "btn-clean" );
// -------------------eventos-------------------------- //
textIn.focus();
btnEncrypt.addEventListener("click", encrypt);
btnDecrypt.addEventListener("click", decrypt);
btnCopiar.addEventListener("click", copy);
btnClean.addEventListener('click', clean);
// ------------------funciones------------------------- //
function validate(text) {
let validation = Boolean(text.match(/[A-ZÀ-ÖØ-öø-ÿ\u00E0-\u00FC]/));
return validation;
}
function encrypt() {
let encryptedText = textIn.value;
if (validate(encryptedText) == true) {
textIn.value = "Sólo letras minúsculas, sin acento, ni carateres especiales";
setTimeout(clean, 5000);
}
else {
encryptedText = encryptedText.replace(/e/img, "enter");
encryptedText = encryptedText.replace(/i/img, "imes");
encryptedText = encryptedText.replace(/a/img, "ai");
encryptedText = encryptedText.replace(/o/img, "ober");
encryptedText = encryptedText.replace(/u/img, "ufat");
encryptedText = encryptedText.replace(/''/img, "");
textOut.classList.toggle("radiationS");
textOut.innerHTML = encryptedText;
textOut.focus();
}
}
function decrypt() {
let encryptedText = textIn.value;
if (validate(encryptedText) == true) {
textIn.value = "Sólo se aceptan minúsculas y palabras sin acento";
setTimeout(clean, 5000);
}
else {
encryptedText = encryptedText.replace (/enter/img, "e");
encryptedText = encryptedText.replace (/imes/img, "i");
encryptedText = encryptedText.replace (/ai/img, "a");
encryptedText = encryptedText.replace (/ober/img, "o");
encryptedText = encryptedText.replace (/ufat/img, "u");
encryptedText = encryptedText.replace (/''/img, "");
textOut.classList.toggle("radiationS");
textOut.innerHTML = encryptedText;
textOut.focus();
}
}
function copy() {
if (textOut.value !== "") {
textOut.select();
textOut.setSelectionRange(0, 99999);
navigator.clipboard.writeText(textOut.value);
textOut.innerHTML = "Tu mensaje se ha copiado correctamente";
}
}
function clean() {
textIn.value = "";
textOut.value = "";
textIn.placeholder = "Ingrese el texto...";
textOut.placeholder = "No se encontró ningún texto";
textIn.focus();
location.reload();
}