-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
102 lines (55 loc) · 1.84 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
95
96
97
98
99
100
101
102
//JavaScript:
//Insertando variables desde HTML
var texto = document.getElementById("texto");
var botonE = document.getElementById("botonE");
botonE.addEventListener("click", clickE);
var textofinal = document.getElementById("textofinal");
var botonD = document.getElementById("botonD");
botonD.addEventListener("click", clickD);
var botonC = document.getElementById("botonC");
botonC.addEventListener("click", clickC);
texto.focus();
var character = document.getElementById("texto").value;
const regex = /[^a-z !ñ]+/
//Funciones:
//Función Encriptar
function clickE() {
//Validadores de carácteres especiales y mayúsculas
if (texto.value.match(regex))
{alert ("No utilizar números, mayúsculas ni carácteres especiales")}
else
//Ejecución de la codificación
{
var cadena =document.getElementById("texto").value;
cadena=cadena.replaceAll("e", "enter");
cadena=cadena.replaceAll("i", "imes");
cadena=cadena.replaceAll("o", "ober");
cadena=cadena.replaceAll("a", "ai");
cadena=cadena.replaceAll("u", "ufat");
textofinal.value=cadena
}
}
//Función Desencriptar
function clickD() {
//Validadores de carácteres especiales y mayúsculas
if (texto.value.match(regex))
{alert ("No utilizar números, mayúsculas ni carácteres especiales")}
else
//Ejecución de la decodificación
{
var cadena =document.getElementById("texto").value;
cadena=cadena.replaceAll("enter", "e");
cadena=cadena.replaceAll("imes", "i");
cadena=cadena.replaceAll("ober", "o");
cadena=cadena.replaceAll("ufat", "u");
cadena=cadena.replaceAll("ai", "a");
textofinal.value=cadena
}
}
//Función Copiar
function clickC() {
var content = document.getElementById('textofinal');
content.select();
document.execCommand('copy');
alert("¡Copiado!");
}