-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
108 lines (87 loc) · 3.41 KB
/
script.js
File metadata and controls
108 lines (87 loc) · 3.41 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
//FUNCION IMAGENES
var fondos = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
var fondosError = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
var fondo = document.getElementById('imagen');
var indicFondo = 0;
function cambiarFondo() {
indicFondo = Math.floor(Math.random() * fondos.length);
fondo.src = `./mtr/${fondos[indicFondo]}.png`;
}
function fondoError() {
indicFondo = Math.floor(Math.random() * fondosError.length);
fondo.src = `./error/${fondosError[indicFondo]}.png`;
}
function imprimirError() {
document.getElementById('pizarra').innerHTML = "¡Ups, no se aceptan mayúsculas, acentos o caracteres especiales!";
fondoError();
document.getElementById('botoncopiar').style.display = 'none';
}
/*La letra "e" es convertida para "enter"
La letra "i" es convertida para "imes"
"La letra "o" es convertida para "ober
La letra "a" es convertida para "ai"
La letra "u" es convertida para "ufat"*/
//FUNCIÓN ENCRIPTAR
var btnEncriptar = document.getElementById('encriptar');
const restriccion = /[^a-z\s?]+/gm;
function encriptacion() {
let texto = document.getElementById('parrafo').value;
if (texto.length == 0) {
document.getElementById('pizarra').innerHTML = "No se encontró ningún texto";
fondoError();
document.getElementById('botoncopiar').style.display = 'none';
}
else {
let error = texto.match(restriccion);
if (error == null) {
let textoEncriptado = texto.replaceAll('e', 'enter').replaceAll('i', 'imes').replaceAll('o', 'ober').replaceAll('a', 'ai').replaceAll('u', 'ufat');
document.getElementById('pizarra').innerHTML = textoEncriptado;
cambiarFondo();
document.getElementById('botoncopiar').style.display = 'flex';
document.getElementById('parrafo').value = "";
}
else {
imprimirError();
}
}
}
btnEncriptar.addEventListener('click', encriptacion);
//FUNCION DESENCRIPTAR
var btnDesencriptar = document.getElementById('desencriptar');
function desencriptacion() {
let texto = document.getElementById('parrafo').value;
if (texto.length == 0) {
document.getElementById('pizarra').innerHTML = "No se encontró ningún texto";
fondoError();
document.getElementById('botoncopiar').style.display = 'none';
}
else {
let error = texto.match(restriccion);
if (error == null) {
let textoDesencriptado = texto.replaceAll('ufat', 'u').replaceAll('ai', 'a').replaceAll('ober', 'o').replaceAll('imes', 'i').replaceAll('enter', 'e');
document.getElementById('pizarra').innerHTML = textoDesencriptado;
cambiarFondo();
document.getElementById('botoncopiar').style.display = 'flex';
document.getElementById('parrafo').value = "";
}
else {
imprimirError();
}
}
}
btnDesencriptar.addEventListener('click', desencriptacion);
//FUNCION COPIAR
const copiador = document.getElementById('copiar');
function leer() {
let texto = document.getElementById('pizarra').textContent;
return texto;
}
async function copiar() {
let txt = leer();
await navigator.clipboard.writeText(txt);
document.getElementById('copiar').textContent = "¡Copiado!"
document.getElementById('copiar').style.color = "white"
setTimeout(() => document.getElementById('copiar').textContent = "Copiar", 1000);
setTimeout(() => document.getElementById('copiar').style.color = "black", 1000);
}
copiador.addEventListener('click', copiar);