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 /main.js | |
| parent | 7aadab4fa063c022d4f31621177e8918ff97a25d (diff) | |
convert function completely finished
Diffstat (limited to 'main.js')
| -rw-r--r-- | main.js | 50 |
1 files changed, 47 insertions, 3 deletions
@@ -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 |
