Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
feat(localstorage): add toggle local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
tikrack committed Sep 10, 2024
1 parent ae188ec commit d7834f0
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions script/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const elm_header = document.querySelector('header');
// Variables
let isReady = false;
let toggleStatus = 0

// Global variables
var Module = {
noInitialRun: true,
Expand Down Expand Up @@ -53,7 +52,7 @@ const displayError = (text) => {
elm_error.textContent += text + '<br>';
};

const toggleIframePosition = () => {
const toggleIframePositiogit n = () => {
if (elm_iframe.style.right === "50%") {
elm_iframe.style.right = "150%";
} else {
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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();
}
Expand All @@ -193,6 +204,7 @@ elm_toggle.addEventListener("change", () => {
}else {
toggleStatus = 0
}
localStorage.setItem("toggle", toggleStatus)
togglePosition()
})

Expand Down

0 comments on commit d7834f0

Please sign in to comment.