-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
74 lines (60 loc) · 2.43 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
66
67
68
69
70
71
72
73
74
console.log('JavaScript cargado.')
let entradaTexto = document.querySelector('#ingresar_mensaje');
let salidaTexto = document.querySelector('#mensaje_contenido');
const areaTexto = document.getElementById('ingresar_mensaje');
areaTexto.addEventListener('input', function() {
areaTexto.value = removeCaracteresEspeciales(removeAcentos(areaTexto.value));
});
function removeAcentos(text) {
return text.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
}
function removeCaracteresEspeciales(text) {
return text.replace(/[^a-zA-Z0-9 ]/g, '');
}
function encriptar() {
console.log("Encriptar botón clickeado");
let text = entradaTexto.value.trim();
if (text === '') {
alerta01();
return;
}
let encriptadoTexto = text.replace(/e/g, 'enter')
.replace(/i/g, 'imes')
.replace(/a/g, 'ai')
.replace(/o/g, 'ober')
.replace(/u/g, 'ufat');
salidaTexto.innerHTML = '<textarea readonly id="texto_salida">' + encriptadoTexto + '</textarea>' +
'<button class="boton_copiar" id="copiar" onclick="copiar()">Copiar</button>';
}
function desencriptar() {
console.log("Desencriptar botón clickeado");
let text = entradaTexto.value.trim();
if (text === '') {
alerta02();
return;
}
let desencriptadoTexto = text.replace(/enter/g, 'e')
.replace(/imes/g, 'i')
.replace(/ai/g, 'a')
.replace(/ober/g, 'o')
.replace(/ufat/g, 'u');
salidaTexto.innerHTML = '<textarea readonly id="texto_salida">' + desencriptadoTexto + '</textarea>' +
'<button class="boton_copiar" id="copiar" onclick="copiar()">Copiar</button>';
}
function copiar() {
let copiarTexto = document.getElementById('texto_salida');
copiarTexto.select();
document.execCommand('copy');
}
function resetContenido() {
salidaTexto.innerHTML = '<img src="./assets/pink_flowers.png" alt="">' +
'<h1>Ningún mensaje fue encontrado</h1>' +
'<h3>Ingresa el texto que desees encriptar o desencriptar.</h3>';
}
function alerta01() {
alert('Por favor, ingrese el mensaje que desea encriptar.');
}
function alerta02() {
alert('Por favor, ingrese el mensaje que desea desencriptar.');
}
resetContenido();