-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
65 lines (54 loc) · 2.19 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
//Secure Cookies
document.cookie = "promo_shown=1; Max-Age=2600000; Secure";
//Texto a LowerCase
function min(e) {
e.value = e.value.toLowerCase();
}
// Solo Letras y Espacio
document.getElementById("texto-codigo").addEventListener("keypress",verificar);
function verificar(e) {
if(e.key.match(/[a-z\s]/i)===null) {
// Si la tecla pulsada no es la correcta se elimina
e.preventDefault();
}
}
// BTN ENCRIPTAR
function encriptar() {
const texto = document.getElementById("texto-codigo").value.toLowerCase();
const textoCodificado = texto.replace(/e/gi, "enter")
.replace(/i/gi, "imes")
.replace(/a/gi, "ai")
.replace(/o/gi, "ober")
.replace(/u/gi, "ufar");
if (texto.length > 0) {
document.getElementById("mostrar-texto").textContent = "Encriptado Exitoso";
document.getElementById("area-mensaje").textContent = textoCodificado;
} else {
swal("Alerta", "Debes ingresar un texto", "warning");
}
}
//BTN DESENCRIPTAR
function desencriptar() {
const texto = document.getElementById("area-mensaje").value.toLowerCase();
const textoCodificado = texto.replace(/enter/gi, "e")
.replace(/imes/gi, "i")
.replace(/ai/gi, "a")
.replace(/ober/gi, "o")
.replace(/ufar/gi, "u");
if (texto.length > 0) {
document.getElementById("mostrar-texto").textContent = "Desencriptado Exitoso";
document.getElementById("area-mensaje").textContent = textoCodificado;
} else {
swal("Alerta", "Debes ingresar un texto", "warning");
}
}
//BTN COPIAR
async function copiar() {
const textoCodificado = document.getElementById("area-mensaje").value;
if (textoCodificado.length > 0) {
await navigator.clipboard.writeText(textoCodificado);
document.getElementById("mostrar-texto").textContent = "Texto Copiado con Éxito";
} else {
swal("Alerta", "No hay texto para copiar", "warning");
}
}