From b967d8f571c1c206ba0b44cb1d423c2fa737517c Mon Sep 17 00:00:00 2001 From: Najam <85332859+najmiter@users.noreply.github.com> Date: Sat, 27 Jan 2024 22:24:58 +0500 Subject: [PATCH] yabl --- main.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/main.js b/main.js index d9ff683..c135959 100644 --- a/main.js +++ b/main.js @@ -14,7 +14,7 @@ fetch("./settings.json") .then((response) => response.json()) .then((settings) => (Settings = settings)); -document.addEventListener("DOMContentLoaded", () => { +document.addEventListener("DOMContentLoaded", async () => { // i forgot how to do it like a fire-emoji // so i'm gonna do it like a sad-emoji setTimeout(() => { @@ -22,11 +22,9 @@ document.addEventListener("DOMContentLoaded", () => { input_text.style.tabSize = n_spaces; output_text.style.tabSize = n_spaces; - output_text.innerHTML = localStorage.getItem("styled_code") ?? ""; input_text.value = localStorage.getItem("plain_code") ?? ""; }, 100); - }); const is_space = (char) => char === " " || char === "\t"; @@ -249,8 +247,11 @@ const chittify = () => { }; const put_shit_into_local_storage = () => { - localStorage.setItem("styled_code", output_text.innerHTML); - localStorage.setItem("plain_code", input_text.value); + // more sad-emoji stuff + setTimeout(() => { + localStorage.setItem("styled_code", output_text.innerHTML); + localStorage.setItem("plain_code", input_text.value); + }, 100); }; const highlight_n_other_shit = () => { @@ -259,6 +260,8 @@ const highlight_n_other_shit = () => { }; const handle_key_down = (btn) => { + put_shit_into_local_storage(); + if (btn.key === "Tab") { btn.preventDefault(); @@ -296,10 +299,10 @@ document.addEventListener("keyup", (btn) => { hightlight_btn.addEventListener("click", highlight_n_other_shit); input_text.addEventListener("keydown", handle_key_down); output_text.addEventListener("keydown", (btn) => { + put_shit_into_local_storage(); + if (btn.key === "Tab") { btn.preventDefault(); } }); - - // document.getElementById("input-text").addEventListener("input", chittify); // React but O(n)