-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (58 loc) · 1.64 KB
/
script.js
File metadata and controls
65 lines (58 loc) · 1.64 KB
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
const inputEl = document.getElementById("input");
const numberEl = document.getElementById("number");
const outputEl = document.getElementById("output");
const convertEl = document.getElementById("convert");
const toggleEl = document.getElementById("toggle");
const copyEl = document.getElementById("copy");
let ENCODE = "0";
let DECODE = "1";
let MODE = ENCODE;
function copy_text(text) {
//Before we copy, we are going to select the text.
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
//add to clipboard.
document.execCommand("copy");
}
inputEl.addEventListener("focus", () => {
inputEl.select();
});
// numberEl.addEventListener('focus', () => {
// numberEl.select()
// })
toggleEl.addEventListener("click", () => {
MODE = MODE == ENCODE ? DECODE : ENCODE;
convertEl.innerText = MODE == ENCODE ? "ENCODE!" : "DECODE!";
});
convertEl.addEventListener("click", () => {
if (inputEl.value.trim()) {
let outputText;
if (MODE == ENCODE) {
outputText = encode(
inputEl.value.trim(),
// Number.parseInt(numberEl.value)
1
);
} else {
outputText = decode(
inputEl.value.trim(),
// Number.parseInt(numberEl.value)
1
);
}
outputEl.innerText = outputText;
if (outputEl.innerText.trim()) {
outputEl.style.border = "3px solid white";
copyEl.style.display = "block";
} else {
outputEl.style.border = "none";
copyEl.style.display = "none";
}
}
});
copyEl.addEventListener("click", () => {
copy_text(outputEl);
});