From d7834f012a678601cec3b6b0fde9c85c59156114 Mon Sep 17 00:00:00 2001 From: mohamadreza Date: Wed, 11 Sep 2024 01:14:57 +0330 Subject: [PATCH] feat(localstorage): add toggle local storage --- script/script.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/script/script.js b/script/script.js index 98d9f09..f193ddc 100644 --- a/script/script.js +++ b/script/script.js @@ -12,7 +12,6 @@ const elm_header = document.querySelector('header'); // Variables let isReady = false; let toggleStatus = 0 - // Global variables var Module = { noInitialRun: true, @@ -53,7 +52,7 @@ const displayError = (text) => { elm_error.textContent += text + '
'; }; -const toggleIframePosition = () => { +const toggleIframePositiogit n = () => { if (elm_iframe.style.right === "50%") { elm_iframe.style.right = "150%"; } else { @@ -85,6 +84,16 @@ const togglePosition = () => { } }; +const checkDefault = () => { + if (localStorage.getItem("toggle")) { + toggleStatus = parseInt(localStorage.getItem("toggle")) + toggleStatus === 1 ? elm_toggle.checked = true : false + }else { + toggleStatus = 0 + } + togglePosition(); +} + const getIframeContent = (iframe) => { return iframe.contentDocument || iframe.contentWindow.document; }; @@ -182,6 +191,8 @@ elm_code.addEventListener("input", () => { window.addEventListener('load', () => { elm_code.focus(); + checkDefault(); + if (localStorage.getItem("cache-code")) { elm_code.value = localStorage.getItem("cache-code").toString().trim(); } @@ -193,6 +204,7 @@ elm_toggle.addEventListener("change", () => { }else { toggleStatus = 0 } + localStorage.setItem("toggle", toggleStatus) togglePosition() })