-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
187 lines (159 loc) · 4.83 KB
/
Copy pathscript.js
File metadata and controls
187 lines (159 loc) · 4.83 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
var mensaje1 = document.getElementsByName("mensaje1");
var mensaje2 = document.getElementsByName("mensaje2");
var btnEncriptar = document.getElementsByName("encriptar");
var btnDesencriptar = document.getElementsByName("desencriptar");
var dic = {
e: "enter",
i: "imes",
a: "ai",
o: "ober",
u: "ufat",
};
let criterio = "^[a-z0-9\\s]+$";
let exp_reg = new RegExp(criterio);
function encriptar() {
let texto = document.querySelectorAll("textarea")[0].value;
//Eliminamos caracteres no deseados
texto = texto.split('');
texto = texto.filter((el) => {
return exp_reg.test(el);
});
texto = texto.join('');
let result = "";
if (
texto.indexOf(dic["a"]) >= 0 ||
texto.indexOf(dic["e"]) >= 0 ||
texto.indexOf(dic["i"]) >= 0 ||
texto.indexOf(dic["o"]) >= 0 ||
texto.indexOf(dic["u"]) >= 0
) {
var notification = new Notification(
"El mensaje ya se encuentra encriptado"
);
setTimeout(function () {
notification.close();
}, 2000);
alert("El mensaje ya se encuentra encriptado");
} else {
for (let i = 0; i < texto.length; i++) {
if (dic[texto[i]]) {
result += dic[texto[i]];
} else {
result += texto[i];
}
}
if (result.length > 0) {
document
.querySelectorAll("textarea")[1]
.setAttribute("class", "textarea-dec");
document.getElementById("textarea-background-id").style.display =
"none";
document.getElementById("copiar").style.display = "block";
var notification = new Notification(
"El mensaje ha sido encriptado"
);
setTimeout(function () {
notification.close();
}, 2000);
} else {
document
.querySelectorAll("textarea")[1]
.setAttribute("class", "no-visible");
document.getElementById("textarea-background-id").style.display =
"block";
document.getElementById("copiar").style.display = "none";
}
document.querySelectorAll("textarea")[1].value = result;
}
}
function replaceTextDic(texto) {
let result = texto;
for (var i in dic) {
result = result.replaceAll(dic[i], i);
}
if (result.length > 0) {
document
.querySelectorAll("textarea")[1]
.setAttribute("class", "textarea-dec");
} else {
document
.querySelectorAll("textarea")[1]
.setAttribute("class", "no-visible");
}
return result;
}
function desencriptar() {
let texto = document.querySelectorAll("textarea")[0].value;
//Eliminamos caracteres no deseados
texto = texto.split('');
texto = texto.filter((el) => {
return exp_reg.test(el);
});
texto = texto.join('');
let result = "";
result = replaceTextDic(texto);
document.querySelectorAll("textarea")[1].value = result;
if (result.length > 0) {
document.getElementById("textarea-background-id").style.display =
"none";
document.getElementById("copiar").style.display = "block";
var notification = new Notification(
"El mensaje ha sido desencriptado"
);
setTimeout(function () {
notification.close();
}, 2000);
} else {
document.getElementById("textarea-background-id").style.display =
"block";
document.getElementById("copiar").style.display = "none";
}
}
function copiarTextClipBoard_v1() {
let texto = document.querySelectorAll("textarea")[1];
let copy = texto.select();
document.execCommand("copy");
var notification = new Notification("El mensaje ha sido copiado");
setTimeout(function () {
notification.close();
}, 2000);
alert("Copied!");
}
function copiarAlPortapapelesOK() {
let textarea = document.querySelectorAll("textarea")[1].select();
document.execCommand("copy");
}
function copiarAlPortapapeles() {
// Creamos un campo de texto "oculto"
var aux = document.createElement("textarea");
// Añadimos el campo a la página
document.body.appendChild(aux);
let texto = document.querySelectorAll("textarea")[1].value;
// Asignamos el contenido del elemento
aux.setAttribute("value", texto);
aux.value = texto;
aux.setAttribute("readonly", "");
// Seleccionamos todo el contenido del campo
aux.select();
// Copiamos el texto seleccionado
document.execCommand("copy");
// Eliminamos el campo de la página
document.body.removeChild(aux);
var notification = new Notification("El mensaje ha sido copiado");
setTimeout(function () {
notification.close();
}, 2000);
}
var rodapie =
"Luis Lozano - " +
"Github: https://github.com/Lozanolc - " +
"LinkedIn: https://www.linkedin.com/in/luis-lozano-bb3820235/ ";
function scroll() {
document.frm.w.value = rodapie;
rodapie = rodapie.substring(1, rodapie.length) + rodapie.charAt(0);
window.setTimeout("scroll()", 150);
}
function classToggleAnimation() {
var el = document.querySelector(".icon-cards__content");
el.classList.toggle("step-animation");
}