From 50c2264a3b7e7ff47742d9d756ce92b88b90e0a7 Mon Sep 17 00:00:00 2001 From: Max Base Date: Wed, 18 Sep 2024 12:46:23 +0330 Subject: [PATCH] fix firefox bug #15 --- public/assets/salam/script/script.js | 36 +++++++++++++++------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/public/assets/salam/script/script.js b/public/assets/salam/script/script.js index 2f54c1a..1f37e84 100644 --- a/public/assets/salam/script/script.js +++ b/public/assets/salam/script/script.js @@ -158,27 +158,27 @@ elm_code.addEventListener('keydown', (event) => { }); elm_code.addEventListener("input", () => { - localStorage.setItem("code", elm_code.value) - elm_copy_code.value = elm_code.value - runSalam(false); + localStorage.setItem("code", elm_code.value) + elm_copy_code.value = elm_code.value + runSalam(false); }); elm_run_code.addEventListener("click", () => { - elm_copy_code.value = elm_code.value - runSalam(false) + elm_copy_code.value = elm_code.value + runSalam(false) }) elm_refactor.addEventListener("click", () => { - runLint() + runLint() }) elm_save.addEventListener("click", (e) => { - if (elm_title.classList.contains("hidden")){ - e.preventDefault() - elm_title.classList.remove("hidden") - elm_title.classList.remove("w-0") - elm_title.classList.remove("p-0") - } + if (elm_title.classList.contains("hidden")){ + e.preventDefault() + elm_title.classList.remove("hidden") + elm_title.classList.remove("w-0") + elm_title.classList.remove("p-0") + } }) // Init @@ -189,10 +189,14 @@ document.body.appendChild(script); window.addEventListener('load', () => { elm_code.focus(); - if (elm_code.value.trim() === ""){ - elm_code.value = localStorage?.getItem("code") - } - elm_copy_code.value = elm_code.value + + if (elm_code.value.trim() === "") { + if (localStorage && localStorage.getItem) { + elm_code.value = localStorage.getItem("code"); + } + } + + elm_copy_code.value = elm_code.value; }); // Cache