-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
71 lines (62 loc) · 2.09 KB
/
script.js
File metadata and controls
71 lines (62 loc) · 2.09 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
const entradaTexto = document.querySelector(".entrada-texto");
const salidaTexto = document.querySelector(".salida-texto");
const seccionTexto1 = document.querySelector(".texto1");
const seccionTexto2 = document.querySelector(".texto2");
const btnCopiar = document.querySelector(".copiar");
// Regular expression to validate only lowercase letters
const letrasInvalidas = /[A-Z]/;
function validar(texto) {
if (letrasInvalidas.test(texto)) {
alert("Texto inválido. Solo se permiten letras minúsculas.");
return false;
}
return true;
}
const encriptarMap = { a: "ai", e: "enter", i: "imes", o: "ober", u: "ufat" };
const desencriptarMap = {
ai: "a", enter: "e", imes: "i", ober: "o", ufat: "u"
};
function encriptar() {
const texto = entradaTexto.value;
if (!validar(texto)) {
return;
}
const salida = texto.replace(/[aeiou]/g, match => encriptarMap[match]);
actualizarSalida(salida);
}
function desencriptar() {
const texto = entradaTexto.value;
if (!validar(texto)) {
return;
}
const salida = texto.replace(/ai|enter|imes|ober|ufat/g, match => desencriptarMap[match]);
actualizarSalida(salida);
}
function actualizarSalida(salida) {
entradaTexto.value = "";
salidaTexto.value = salida;
ocultar();
}
function ocultar() {
salidaTexto.style.background = "white";
seccionTexto1.style.display = "none";
seccionTexto2.style.display = "none";
btnCopiar.style.display = "inline";
}
function mostrar() {
salidaTexto.style.background = "#FFF no-repeat center url(imagenes/notexto.png)";
seccionTexto1.style.display = "block";
seccionTexto2.style.display = "block";
btnCopiar.style.display = "none";
}
function copiar() {
navigator.clipboard.writeText(salidaTexto.value);
const anuncio = document.querySelector(".anuncio");
anuncio.textContent = "Texto copiado";
anuncio.style.display = "block";
setTimeout(() => {
anuncio.style.display = "none";
salidaTexto.value = "";
mostrar();
}, 950);
}