summaryrefslogtreecommitdiff
path: root/main.js
diff options
context:
space:
mode:
authormrdog233o5 <mr.dog233o5@gmail.com>2024-04-09 14:33:07 +0800
committermrdog233o5 <mr.dog233o5@gmail.com>2024-04-09 14:43:32 +0800
commit261cc5899f00a661aa3bfa528b2d7a4f625593e7 (patch)
tree85d4aea1c859233918de64a98deea96c427fc339 /main.js
parent7aadab4fa063c022d4f31621177e8918ff97a25d (diff)
convert function completely finished
Diffstat (limited to 'main.js')
-rw-r--r--main.js50
1 files changed, 47 insertions, 3 deletions
diff --git a/main.js b/main.js
index eff37dc..7c1e830 100644
--- a/main.js
+++ b/main.js
@@ -90,6 +90,50 @@ MÂ
<¯
>˘
?¿`.split("\n");
-match.forEach((idk) => {
- console.log(idk);
-}) \ No newline at end of file
+const modeBtn = document.getElementById("modeBtn");
+const convertBtn = document.getElementById("convertBtn");
+const input = document.getElementById("input");
+const output = document.getElementById("output");
+const copyBtn = document.getElementById("copyBtn");
+var mode = true;
+
+function convert(input, mode) {
+ input = input.split("");
+ var result = "";
+ var fromIndex = 0;
+ var toIndex = 0;
+ if (mode) {
+ toIndex = 1;
+ } else {
+ fromIndex = 1;
+ }
+ // loop through each char
+ input.forEach((char) => {
+ // match this char
+ for (var i = 0; i < match.length; i++) {
+ if (char == match[i][fromIndex]) {
+ result += match[i][toIndex];
+ return;
+ }
+ }
+ })
+ return result;
+}
+
+modeBtn.addEventListener("click", () => {
+ mode = !mode;
+ if (mode) {
+ modeBtn.innerText = "normal text > encrypted text";
+ } else {
+ modeBtn.innerText = "encrypted text > normal text";
+ }
+});
+
+convertBtn.addEventListener("click", () => {
+ var res = convert(input.value, mode);
+ output.innerText = res;
+});
+
+copyBtn.addEventListener("click", () => {
+ navigator.clipboard.writeText(output.innerText);
+}); \ No newline at end of file