-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
94 lines (75 loc) · 2.99 KB
/
index.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
// Reemplazo de vocales
// a = ai
// e = enter
// i = imes
// o = ober
// u = ufat
// funcion para encriptar
function encrypt() {
// tomo el valor del texto escrito
var text = document.getElementById("text").value;
// expresion regular para los ascentos
var expReg = /[áéíóú]/gm;
// valido que el texto este en minusculas y sin ascentos
if ((text == text.toLowerCase()) && (expReg.test(text) == false)){
// reemplazo las vocales con el metodo .replace + midificadores por las vocales cifradas
var textEncrypt = text.replace(/e/gm,"enter");
var textEncrypt = textEncrypt.replace(/o/gm,"ober");
var textEncrypt = textEncrypt.replace(/i/gm,"imes");
var textEncrypt = textEncrypt.replace(/a/mg,"ai");
var textEncrypt = textEncrypt.replace(/u/gm,"ufat");
// oculto el 1er contenedor y muestro el 2do
document.getElementById("container-decrypt").style.display = "none";
document.getElementById("container-decrypted").style.display = "inline-block";
// inserto el texto desifrado en el <p> asignado
document.getElementById("t-copied").innerHTML = textEncrypt;
}
else {
// Alerta recordatorio (a mejorar esta comunicacion con posible modal...)
alert ("Recuerde solo letras minúsculas y sin ascentos");
}
}
document.getElementById("b-encrypt").onclick = function(){
encrypt();
}
// funcion para desencriptar
function decrypt(){
var text = document.getElementById("text").value.toLowerCase();
var textDecrypt = text.replace(/enter/gm,"e");
var textDecrypt = textDecrypt.replace(/ober/gm,"o");
var textDecrypt = textDecrypt.replace(/imes/gm,"i");
var textDecrypt = textDecrypt.replace(/ai/gm,"a");
var textDecrypt = textDecrypt.replace(/ufat/gm,"u");
document.getElementById("container-decrypt").style.display = "none";
document.getElementById("container-decrypted").style.display = "inline-block";
document.getElementById("t-copied").innerHTML = textDecrypt;
}
document.getElementById("b-decrypt").onclick = function(){
decrypt();
}
// funcion para el boton copiar
// tomo el contenido a copiar
const eCopy = document.querySelector(".container-copy")
function copy(element){
// creo un input externo
const inputO = document.createElement("input");
// se le da valor
inputO.setAttribute("value", element.innerText);
// lo agrego al documento por medio del appendChild
document.body.appendChild(inputO);
// se toma el contenido
inputO.select();
// y se copia
document.execCommand("copy");
// quito el Child con remove
document.body.removeChild(inputO);
}
// button alert (igual a mejorar...)
function copyAlert(){
alert ("¡Mensaje copiado!");
}
// copio y activo el button alert de copiado
document.querySelector("#b-copy").addEventListener("click", ()=>{
copy(eCopy);
copyAlert();
})