-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
75 lines (65 loc) · 2.13 KB
/
app.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
75
const plainText = document.getElementById('textarea')
const copy = document.getElementById('copy-btn')
const encriptarBtn = document.getElementById('encriptar')
const desencriptarBtn = document.getElementById('desencriptar')
const containerData = document.getElementById('data-list')
const initialState = document.getElementById('initial_state')
const data =document.getElementById('data')
const encriptar = () => {
const data = plainText.value
let newdata=''
for (let i = 0; i < data.length; i++) {
if (data[i] === 'a') {
newdata+="ai"
} else if (data[i] === 'e') {
newdata+="enter"
} else if (data[i] === 'i') {
newdata+="imes"
} else if (data[i] === 'o') {
newdata+="ober"
} else if (data[i] === 'u') {
newdata+="ufat"
} else if (data[i] === ' ') {
newdata+="sp"
}else{
newdata+=data[i]
}
}
return newdata
}
const desencriptar = () => {
var chars = {'ai':'a','enter':'e','imes':'i', 'ober': 'o', 'ufat':'u', 'sp':' '};
const encripted = plainText.value
const desencripted =encripted.replace(/ai|enter|imes|ober|ufat|sp/g, m => chars[m])
return desencripted
}
encriptarBtn.addEventListener('click', ()=> {
if(plainText.value ===''){
alert("Es necesario que agregues texto para encriptarlo.");
} else{
copy.style.display='block'
data.style.display='block'
initialState.style.display='none'
data.innerHTML= encriptar()
plainText.value=''
}
})
desencriptarBtn.addEventListener('click', ()=>{
if(plainText.value ===''){
alert("Es necesario que agregues texto para desencriptarlo.");
} else{
initialState.style.display='none'
data.style.display='block'
copy.style.display='block'
data.innerHTML= desencriptar()
plainText.value=''
}
})
const copyClipboard=()=> {
const copyText = document.getElementById('data').innerHTML
navigator.clipboard.writeText(copyText);
alert("texto se ha copiado: " + copyText);
}
copy.addEventListener('click', ()=>{
copyClipboard()
})