-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
70 lines (53 loc) · 1.53 KB
/
script.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
"use strict";
let btnEncrypt = document.getElementById("btn-encrypt");
let btnDecrypt = document.getElementById("btn-decrypt");
let btnCopy = document.getElementById("btn-copy");
let btnClear = document.getElementById("btn-clear");
let input = document.getElementById("input");
let output = document.getElementById("output");
let encrypt = function (e) {
e.preventDefault();
let inputText = input.value
.toLowerCase()
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "");
inputText = inputText
.replaceAll("e", "enter")
.replaceAll("i", "imes")
.replaceAll("a", "ai")
.replaceAll("u", "ufat")
.replaceAll("o", "ober");
output.value = inputText;
};
let decrypt = function (e) {
e.preventDefault();
let inputText = input.value
.toLowerCase()
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "");
inputText = inputText
.replaceAll("enter", "e")
.replaceAll("imes", "i")
.replaceAll("ai", "a")
.replaceAll("ufat", "u")
.replaceAll("ober", "o");
output.value = inputText;
};
let copy = function () {
navigator.clipboard.writeText(output.value);
// Segunda manera de hacerlo, pero considerada obsoleta:
/* output.select();
document.execCommand("copy"); */
};
let clear = function () {
if (input.value != "") {
input.value = "";
}
if (output.value != "") {
output.value = "";
}
};
btnEncrypt.addEventListener("click", encrypt);
btnDecrypt.addEventListener("click", decrypt);
btnCopy.addEventListener("click", copy);
btnClear.addEventListener("click", clear);