-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
111 lines (89 loc) · 2.42 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const encryptDict = {
e: "enter",
i: "imes",
a: "ai",
o: "ober",
u: "ufat",
};
const decryptDict = createDecryptDict();
function createDecryptDict() {
const decryptDict = {};
for (let key in encryptDict) {
decryptDict[encryptDict[key]] = key;
}
return decryptDict;
}
function emptyMSG(msg) {
if (msg === "") {
document.getElementById("hideOutput").style.display = "flex";
document.getElementById("showOutput").style.display = "none";
return true;
} else {
document.getElementById("hideOutput").style.display = "none";
document.getElementById("showOutput").style.display = "flex";
return false;
}
}
function getMSG() {
let msg = document.getElementById("text-input").value;
return msg;
}
function encryptMSG() {
let msg = getMSG();
if (emptyMSG(msg)) {
return;
}
msg = msg
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.toLowerCase();
let encryptedMSG = msg.replace(/[eiaou]/g, function (char) {
if (char in encryptDict) {
return encryptDict[char];
} else {
return char;
}
});
document.getElementById("text-output").textContent = encryptedMSG;
}
function decryptMSG() {
let msg = getMSG();
if (emptyMSG(msg)) {
return;
}
msg.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "")
.toLowerCase();
let decryptedMSG = msg.replace(/enter|imes|ai|ober|ufat/g, function (char) {
if (char in decryptDict) {
return decryptDict[char];
} else {
return char;
}
});
document.getElementById("text-output").textContent = decryptedMSG;
}
function copyText() {
let text = document.getElementById("text-output").textContent;
navigator.clipboard.writeText(text);
popup("Texto copiado!");
let copyButton = document.getElementById("btn-copy");
originalValue = copyButton.value;
copyButton.value = "Copiado!";
setTimeout(() => {
copyButton.value = originalValue;
}, 1000);
}
function clearText() {
document.getElementById("text-input").value = "";
encryptMSG();
}
function popup(msg) {
let popup = document.createElement("div");
popup.innerHTML = msg;
popup.classList.add("popup");
document.body.appendChild(popup);
setTimeout(() => {
document.body.removeChild(popup);
}, 1500);
}