-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
60 lines (50 loc) · 2.19 KB
/
main.js
File metadata and controls
60 lines (50 loc) · 2.19 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
const decodificado = document.getElementById("decodificar");
const textarea = document.getElementById("texto_decode");
const btnEncriptar = document.getElementById("encriptar_btn");
const btnDesencriptar = document.getElementById("desencriptar_btn");
function encriptar(msg){
let newMsg=msg.replace(/e/gi, 'enter').replace(/i/gi, 'imes').replace(/a/gi, 'ai').replace(/u/gi, 'ufat').replace(/o/gi, 'ober');
console.log(newMsg);
return newMsg;
}
function desencriptar(msg){
let newMsg=msg.replaceAll('ai', 'a').replaceAll('enter', 'e').replaceAll('ufat', 'u').replaceAll('imes', 'i').replaceAll('ober', 'o');
console.log(newMsg);
return newMsg;
}
function mostrarResultado(modo){
if(textarea.value!=="")
{
decodificado.innerHTML=`
<div class="containerDe">
<div class="textoD" id="textoD">
<p>${modo==="encriptar" ? encriptar(textarea.value) : desencriptar(textarea.value)}</p>
</div>
<button class="copiar" id="copiar">Copiar</button>
</div>`;
const texto = document.getElementById("textoD").innerText;
const btnCopiar = document.getElementById("copiar");
const copiarContenido = async () => {
try {
await navigator.clipboard.writeText(texto);
} catch (err) {
console.error('Error al copiar: ', err);
}
}
btnCopiar.addEventListener("click", e => {
copiarContenido();
document.querySelector('.notification_copy').classList.toggle('inactive');
setTimeout(()=> document.querySelector('.notification_copy').classList.toggle('inactive'), 2000)
})
}
}
textarea.addEventListener('keydown', e => {
let regex=/[A-ZzäÄëËïÏöÖüÜáéíóúáéíóúÁÉÍÓÚÂÊÎÔÛâêîôûàèìòùÀÈÌÒÙ]/;
if(regex.test(e.key) & e.key!=='Backspace') e.preventDefault();
});
btnEncriptar.addEventListener('click', e => {
mostrarResultado('encriptar');
});
btnDesencriptar.addEventListener('click', e => {
mostrarResultado('desencriptar');
})