diff options
| author | mrdog233o5 <mr.dog233o5@gmail.com> | 2024-04-09 14:33:07 +0800 |
|---|---|---|
| committer | mrdog233o5 <mr.dog233o5@gmail.com> | 2024-04-09 14:43:32 +0800 |
| commit | 261cc5899f00a661aa3bfa528b2d7a4f625593e7 (patch) | |
| tree | 85d4aea1c859233918de64a98deea96c427fc339 | |
| parent | 7aadab4fa063c022d4f31621177e8918ff97a25d (diff) | |
convert function completely finished
| -rw-r--r-- | index.html | 19 | ||||
| -rw-r--r-- | main.js | 50 |
2 files changed, 56 insertions, 13 deletions
@@ -3,18 +3,17 @@ <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Apple converter</title> + <script src="/main.js" defer></script> + <title>Apple comverter</title> </head> <body> - <div class="input"> - <textarea id="input" placeholder="Input Encrypt or Decrypt msg"></textarea> - </div> + <textarea id="input" placeholder="Input Encrypt or Decrypt msg"></textarea> <select id="mode"> - <option value="normal">Normal</option> - <option value="reverse">Reverse</option> + <option value="0">Normal</option> + <option value="1">Reverse</option> </select> - <button id="convert">Convert</button> - <div class="output" id="output"></div> - <script defer src="/main.js"></script> + <button id="convertBtn">convert</button> + <p id="output"></p> + <button id="copyBtn">copy result</button> </body> -</html> +</html @@ -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 |
