From 64583ac7524df51c807d158b1091149456df127d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=9B=D1=83=D0=BA=D0=B0?=
<164436043+diamond-ore@users.noreply.github.com>
Date: Fri, 26 Apr 2024 21:02:16 -0400
Subject: [PATCH] Encode/Decoder Fix
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Hopefully fixes my js, worked locally 🤷♂️
---
_config.yml | 9 ------
404.html => assets/404.html | 0
techdemos/encode/index.markdown | 51 +--------------------------------
techdemos/encode/js/main.js | 42 +++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 59 deletions(-)
rename 404.html => assets/404.html (100%)
create mode 100644 techdemos/encode/js/main.js
diff --git a/_config.yml b/_config.yml
index 84ba4bd..89cc1dd 100644
--- a/_config.yml
+++ b/_config.yml
@@ -66,15 +66,6 @@ defaults:
sass:
style: compressed
-compress_html:
- clippings: all
- comments: all
- endings: all
- profile: false
- blanklines: false
- ignore:
- envs: [development]
-
exclude:
- bin/*
- "*.gem"
diff --git a/404.html b/assets/404.html
similarity index 100%
rename from 404.html
rename to assets/404.html
diff --git a/techdemos/encode/index.markdown b/techdemos/encode/index.markdown
index 16a9c31..e93055f 100644
--- a/techdemos/encode/index.markdown
+++ b/techdemos/encode/index.markdown
@@ -22,53 +22,4 @@ Mode:
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/techdemos/encode/js/main.js b/techdemos/encode/js/main.js
new file mode 100644
index 0000000..f7889e9
--- /dev/null
+++ b/techdemos/encode/js/main.js
@@ -0,0 +1,42 @@
+const mode = document.getElementById("mode");
+const encode = document.getElementById("encode");
+const decode = document.getElementById("decode");
+const livemode = document.getElementById("livemode");
+const input = document.getElementById("inputText");
+const output = document.getElementById("outputText");
+const codes = {
+ "Base64": {
+ encode: text => btoa(text),
+ decode: text => atob(text)
+ },
+ "URL": {
+ encode: text => encodeURI(text),
+ decode: text => decodeURI(text)
+ },
+ "URL (component)": {
+ encode: text => encodeURIComponent(text),
+ decode: text => decodeURIComponent(text)
+ }
+}
+for (const code in codes) {
+ let element = document.createElement("option");
+ element.value = code;
+ element.innerText = code;
+ mode.appendChild(element);
+}
+encode.addEventListener("click", () => {
+ output.value = codes[mode.value].encode(input.value);
+});
+decode.addEventListener("click", () => {
+ input.value = codes[mode.value].decode(output.value);
+});
+input.addEventListener("input", () => {
+ if (livemode.checked) {
+ output.value = codes[mode.value].encode(input.value);
+ }
+});
+output.addEventListener("input", () => {
+ if (livemode.checked) {
+ input.value = codes[mode.value].decode(output.value);
+ }
+});
\ No newline at end of file