From 261cc5899f00a661aa3bfa528b2d7a4f625593e7 Mon Sep 17 00:00:00 2001 From: mrdog233o5 Date: Tue, 9 Apr 2024 14:33:07 +0800 Subject: convert function completely finished --- index.html | 19 +++++++++---------- main.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 56e87ba..cf88829 100644 --- a/index.html +++ b/index.html @@ -3,18 +3,17 @@ - Apple converter + + Apple comverter -
- -
+ - -
- + +

+ - +˘ ?¿`.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 -- cgit v1.2.3