-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
74 lines (68 loc) · 2.1 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
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
function validateCaracters() {
let caracPermitted = /^[a-z\s\!\?]{0,}$/;
textToEncrypt.value.match(caracPermitted) ? encrypt() : informInvalid();
}
function informInvalid() {
show_invalid_input = document.getElementById("if_invalid_input").innerHTML =
"ⓘ Only lowercase letters and no accents";
}
function encrypt() {
let changeTxt = {
a: "ai",
e: "enter",
i: "imes",
o: "ober",
u: "ufat",
};
let textEncrypted = textToEncrypt.value.replace(
/[aeiou]/g,
(c) => changeTxt[c]
);
let show = (document.getElementById("show_Encrypt").innerHTML =
textEncrypted);
textToEncrypt.value = "";
show_invalid_input = document.getElementById("if_invalid_input").innerHTML =
"";
}
//OPTION-2-for-decrypt//
function decrypt() {
let changeTxtBack = textToEncrypt.value
.replace(/ai/g, "a")
.replace(/enter/g, "e")
.replace(/imes/g, "i")
.replace(/ober/g, "o")
.replace(/ufat/g, "u");
let show = (document.getElementById("show_Encrypt").innerHTML =
changeTxtBack);
textToEncrypt.value = "";
}
function copyEncrypt() {
let textToCopy = document.getElementById("show_Encrypt");
textToCopy.select();
navigator.clipboard.writeText(textToCopy.value);
}
let show_invalid_input = "";
let textToEncrypt = document.querySelector("#text_To_Encrypt");
// textToEncrypt.focus();//removed for now.11082022
let button_doEncrypt = document.querySelector("#do_Encrypt");
button_doEncrypt.onclick = validateCaracters;
let button_doDecrypt = document.querySelector("#do_Decrypt");
button_doDecrypt.onclick = decrypt;
let button_copyEncrypt = document.querySelector("#copy_Encrypt");
button_copyEncrypt.onclick = copyEncrypt;
// option-1 THIS OPTION does not DECRYPT WORD INTO SHOW TEXTAREA(FIX) or use OPTION-2
// function decrypt() {
// let changeTxt = {
// ai: "a",
// enter: "e",
// imes: "i",
// ober: "o",
// ufat: "u",
// };
// let textDecrypted = textToEncrypt.value.replace(
// /[ai][enter][imes][ober][ufat]/g,
// (c) => changeTxt[c]
// );
// let show = (document.getElementById("show_Encrypt").innerHTML =
// textDecrypted);
// }