-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodigo.js
42 lines (41 loc) · 1.44 KB
/
codigo.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
var inputMensaje = document.querySelector("#mensaje");
var inputResultado = document.querySelector("#resultado");
var contador = document.getElementById("contador");
var btnEncriptar = document.querySelector("#encriptar");
var btnDesencriptar = document.querySelector("#desencriptar");
var btnCopiar = document.querySelector("#copiar");
function encriptar(){
var mensaje = inputMensaje.value;
var palabraOculta = mensaje.replaceAll("e","enter")
.replaceAll("i","imes")
.replaceAll("a","ai")
.replaceAll("o","ober")
.replaceAll("u","ufat")
.normalize('NFD').replace(/[\u0300-\u036f]/g,"");///quitar acentos
inputResultado.value= palabraOculta;
}
function desencriptar(){
var mensaje = inputMensaje.value;
var desencriptaMensaje = mensaje.replaceAll("enter","e")
.replaceAll("imes","i")
.replaceAll("ai","a")
.replaceAll("ober","o")
.replaceAll("ufat","u");
inputResultado.value= desencriptaMensaje;
}
//funcion para copiar
function copiar(){
var mensajeEncriptado = document.getElementById('resultado');
mensajeEncriptado.select();
document.execCommand('copy');
inputMensaje.value = "";
}
///contar caracteres
inputMensaje.addEventListener("keyup",e=>{
if (inputMensaje.value.length ) {
contador.innerHTML = inputMensaje.value.length;
}
})
btnEncriptar.onclick = encriptar;
btnDesencriptar.onclick = desencriptar;
btnCopiar.onclick= copiar;