-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
1 lines (1 loc) · 2.13 KB
/
main.js
1
const writter=document.querySelector("#writter"),btnEncrypt=document.querySelector("#encrypt"),btnDecrypt=document.querySelector("#decrypt"),displayEncrypt=document.querySelector("#displayEncrypt"),copyText=document.querySelector("#copyText"),haveExtraAnimation=document.querySelector("#have-animation-extra"),toastAlert=document.querySelector("#toastAlert");function encrypt(t){const e={e:"enter",i:"imes",a:"ai",o:"ober",u:"ufat"};return e[t]?e[t]:t}function decrypt(t){let e="";return[{e:/enter/g},{i:/imes/g},{a:/ai/g},{o:/ober/g},{u:/ufat/g}].forEach((a=>{t=t.replace(Object.values(a)[0],Object.keys(a)[0]),e=t})),e}function activeAnimationExtra(t){if("none"===t)return haveExtraAnimation.innerHTML="";haveExtraAnimation.innerHTML='<img class="animation-charge" src="./img/icons/cat.svg" />\n\n '}let switchAnimation="lock",cicle=null;function timer(t){cicle=setInterval((()=>{"lock"===t?t="unlock":"unlock"===t?t="lock":activeAnimationExtra("none"),activeAnimationExtra(t)}))}function toast(t,e){toastAlert.style.opacity="1";let a=`<p class="toastAlert" style="background-color: ${e};">${t}</p>`;toastAlert.innerHTML=a,setTimeout((()=>{toastAlert.style.opacity="0"}),3e3)}function validations(t){return t.match(/[0-9]/g)?"No admite números":t.match(/[A-Z]/g)?"Solo letras minúsculas":t.match(/^[a-z\s]+$/g)?"passed":"No debe tener acentos"}timer(switchAnimation),btnEncrypt.addEventListener("click",(t=>{if(writter.value)if("passed"===validations(writter.value)){activeAnimationExtra("none"),clearInterval(cicle);let t="";for(let e in writter.value)t+=encrypt(writter.value[e]);displayEncrypt.value=t,writter.value=""}else toast(validations(writter.value),"red");else toast("Ingresa un texto","red")})),btnDecrypt.addEventListener("click",(t=>{writter.value?"passed"===validations(writter.value)?(displayEncrypt.value=decrypt(writter.value),writter.value=""):toast(validations(writter.value),"red"):toast("Ingresa un texto","red")})),copyText.addEventListener("click",(async t=>{displayEncrypt.value?(displayEncrypt.focus(),displayEncrypt.select(),toast("Copiado","green"),await navigator.clipboard.writeText(displayEncrypt.value)):toast("Nada que copiar","gray")}));