summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrdog233o5 <mr.dog233o5@gmail.com>2024-04-11 18:32:20 +0800
committermrdog233o5 <mr.dog233o5@gmail.com>2024-04-11 18:33:08 +0800
commit40e85ca1db4a52e8764ac354ec291bb4b1222911 (patch)
tree9eb130cad9682fdf8b47b05019839b2b8827351a
parent42442ebe77e13cb70847d54b5d3be6243508d441 (diff)
auto detect mode
-rw-r--r--website/index.html5
-rw-r--r--website/main.js22
2 files changed, 16 insertions, 11 deletions
diff --git a/website/index.html b/website/index.html
index d6b2e58..89c3538 100644
--- a/website/index.html
+++ b/website/index.html
@@ -9,11 +9,6 @@
<body>
<h1>apple option key convertor</h1>
<textarea id="input" placeholder="Input Encrypt or Decrypt msg"></textarea>
- <select id="mode">
- <option value="0">Normal</option>
- <option value="1">Reverse</option>
- </select>
- <button id="convertBtn">convert</button>
<p id="output"></p>
<button id="copyBtn">copy result</button>
</body>
diff --git a/website/main.js b/website/main.js
index 212e76e..184d2b3 100644
--- a/website/main.js
+++ b/website/main.js
@@ -1,9 +1,6 @@
-const modeBtn = document.getElementById("mode");
-const convertBtn = document.getElementById("convertBtn");
const input = document.getElementById("input");
const output = document.getElementById("output");
const copyBtn = document.getElementById("copyBtn");
-var mode = true;
const match = `\`\`
1ยก
@@ -122,12 +119,25 @@ function convert(input, mode) {
return result;
}
-convertBtn.onclick = event => {
- mode = modeBtn.value == "0" ? false : true;
- var res = convert(input.value, mode);
+function autoConvert() {
+ var mode = null;
+ var res = "";
+ for (var i = 0; i < input.value.length; i++) {
+ if (mode != null) {
+ break;
+ }
+ for (var j = 0; j < match.length; j++) {
+ if (match[j][0] == input.value[i]) mode = true;
+ if (match[j][1] == input.value[i]) mode = false;
+ }
+ }
+ res = convert(input.value, mode);
output.innerText = res;
+ window.requestAnimationFrame(autoConvert);
}
copyBtn.onclick = event => {
navigator.clipboard.writeText(output.innerText);
}
+
+autoConvert(); \ No newline at end of file