-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (39 loc) · 1.06 KB
/
index.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
let charsToEncrypt = {
'a': 'ai',
'e': 'enter',
'i': 'imes',
'o': 'ober',
'u': 'ufat'
}
let charsToDecrypt = {
'ai': 'a',
'enter': 'e',
'imes': 'i',
'ober': 'o',
'ufat': 'u'
}
let inputText = document.querySelector(".input");
let outputText = document.querySelector(".output");
function encrypt(e) {
let string = inputText.value;
string = string.replace(/[aeiou]/g, m => charsToEncrypt[m]);
outputText.value = string;
e.preventDefault();
}
function decrypt(e) {
let string = inputText.value;
string = string.replace(/ai|enter|imes|ober|ufat/g, m => charsToDecrypt[m]);
outputText.value = string;
e.preventDefault();
}
function copy(e) {
outputText.select();
navigator.clipboard.writeText(outputText.value);
e.preventDefault();
}
let encryptButton = document.querySelector(".encrypt");
encryptButton.onclick = encrypt;
let decryptButton = document.querySelector(".decrypt");
decryptButton.onclick = decrypt;
let copyButton = document.querySelector(".copyButton");
copyButton.onclick = copy;