diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index d726e9a64..741ce4f9d 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -441,7 +441,7 @@ export const zoomOut = (protyle: IProtyle, id: string, focusId?: string, isPushB } } if (window.siyuan.mobileEditor) { - window.localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({ + localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({ id, action: id === protyle.block.rootID ? [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT] : [Constants.CB_GET_ALL] })); diff --git a/app/src/mobile/editor.ts b/app/src/mobile/editor.ts index 11c9d8580..af5e077c7 100644 --- a/app/src/mobile/editor.ts +++ b/app/src/mobile/editor.ts @@ -14,7 +14,7 @@ import {hideElements} from "../protyle/ui/hideElements"; import {pushBack} from "./util/MobileBackFoward"; export const openMobileFileById = (id: string, action = [Constants.CB_GET_HL]) => { - window.localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({id, action})); + localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({id, action})); if (window.siyuan.mobileEditor) { hideElements(["toolbar", "hint", "util"], window.siyuan.mobileEditor.protyle); if (window.siyuan.mobileEditor.protyle.contentElement.classList.contains("fn__none")) { diff --git a/app/src/mobile/util/MobileBackFoward.ts b/app/src/mobile/util/MobileBackFoward.ts index 3daf98435..0224abe95 100644 --- a/app/src/mobile/util/MobileBackFoward.ts +++ b/app/src/mobile/util/MobileBackFoward.ts @@ -12,7 +12,7 @@ const forwardStack: IBackStack[] = []; const focusStack = (backStack: IBackStack) => { const protyle = window.siyuan.mobileEditor.protyle; - window.localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({ + localStorage.setItem(Constants.LOCAL_DOCINFO, JSON.stringify({ id: backStack.id, action: backStack.callback, })); diff --git a/app/src/mobile/util/initFramework.ts b/app/src/mobile/util/initFramework.ts index 232138316..5c39e9e5a 100644 --- a/app/src/mobile/util/initFramework.ts +++ b/app/src/mobile/util/initFramework.ts @@ -127,7 +127,7 @@ export const initFramework = () => { }); initEditorName(); if (getOpenNotebookCount() > 0) { - const localDoc = JSON.parse(window.localStorage.getItem(Constants.LOCAL_DOCINFO) || '{"id": ""}'); + const localDoc = JSON.parse(localStorage.getItem(Constants.LOCAL_DOCINFO) || '{"id": ""}'); fetchPost("/api/block/checkBlockExist", {id: localDoc.id}, existResponse => { if (existResponse.data) { openMobileFileById(localDoc.id, localDoc.action); diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts index 1be6b89f3..c1eeede79 100644 --- a/app/src/protyle/util/compatibility.ts +++ b/app/src/protyle/util/compatibility.ts @@ -135,21 +135,20 @@ export const hotKey2Electron = (key: string) => { export const setLocalStorage = () => { fetchPost("/api/storage/getLocalStorage", undefined, (response) => { + localStorage.clear(); if (response.data) { Object.keys(response.data).forEach(item => { - window.localStorage.setItem(item, response.data[item]); + localStorage.setItem(item, response.data[item]); }); - } else { - localStorage.clear(); } }); // 复写 localStorage window.__localStorage__setItem = localStorage.setItem window.__localStorage__removeItem = localStorage.removeItem - localStorage.setItem = function (key, value) { - window.__localStorage__setItem.call(this, key, value) - fetchPost("/api/storage/setLocalStorageVal", {key, value}); + localStorage.setItem = function (key, val) { + window.__localStorage__setItem.call(this, key, val) + fetchPost("/api/storage/setLocalStorageVal", {key, val}); } localStorage.removeItem = function (key) { window.__localStorage__removeItem.call(this, key) @@ -158,7 +157,7 @@ export const setLocalStorage = () => { }; export const exportLocalStorage = (cb: () => void) => { - fetchPost("/api/storage/setLocalStorage", {val: window.localStorage}, () => { + fetchPost("/api/storage/setLocalStorage", {val: localStorage}, () => { cb(); }); }; diff --git a/app/src/protyle/util/insertHTML.ts b/app/src/protyle/util/insertHTML.ts index e1b44fdaa..fe96b8f96 100644 --- a/app/src/protyle/util/insertHTML.ts +++ b/app/src/protyle/util/insertHTML.ts @@ -119,7 +119,7 @@ export const insertHTML = (html: string, protyle: IProtyle, isBlock = false) => replaceInnerHTML += "\n```"; } const languageIndex = replaceInnerHTML.indexOf("```") + 3; - replaceInnerHTML = replaceInnerHTML.substring(0, languageIndex) + (window.localStorage["local-codelang"] || "") + replaceInnerHTML.substring(languageIndex); + replaceInnerHTML = replaceInnerHTML.substring(0, languageIndex) + (localStorage["local-codelang"] || "") + replaceInnerHTML.substring(languageIndex); editableElement.innerHTML = replaceInnerHTML; } diff --git a/app/src/util/history.ts b/app/src/util/history.ts index c577e217c..cdb836461 100644 --- a/app/src/util/history.ts +++ b/app/src/util/history.ts @@ -23,7 +23,7 @@ const renderDoc = (element: HTMLElement, currentPage: number) => { const opElement = element.querySelector('.b3-select[data-type="opselect"]') as HTMLSelectElement; const typeElement = element.querySelector('.b3-select[data-type="typeselect"]') as HTMLSelectElement; const notebookElement = element.querySelector('.b3-select[data-type="notebookselect"]') as HTMLSelectElement; - window.localStorage.setItem(Constants.LOCAL_HISTORYNOTEID, notebookElement.value); + localStorage.setItem(Constants.LOCAL_HISTORYNOTEID, notebookElement.value); const docElement = element.querySelector('.history__text[data-type="docPanel"]'); const assetElement = element.querySelector('.history__text[data-type="assetPanel"]'); const mdElement = element.querySelector('.history__text[data-type="mdPanel"]') as HTMLTextAreaElement; diff --git a/app/src/util/mount.ts b/app/src/util/mount.ts index 2f815b0e3..b19134382 100644 --- a/app/src/util/mount.ts +++ b/app/src/util/mount.ts @@ -25,7 +25,7 @@ export const newDailyNote = () => { }); return; } - const localNotebookId = window.localStorage.getItem(Constants.LOCAL_DAILYNOTEID); + const localNotebookId = localStorage.getItem(Constants.LOCAL_DAILYNOTEID); if (localNotebookId && getNotebookName(localNotebookId) && !isMobile()) { fetchPost("/api/filetree/createDailyNote", { notebook:localNotebookId, @@ -56,7 +56,7 @@ export const newDailyNote = () => { }); btnsElement[1].addEventListener("click", () => { const notebook = selectElement.value; - window.localStorage.setItem(Constants.LOCAL_DAILYNOTEID, notebook); + localStorage.setItem(Constants.LOCAL_DAILYNOTEID, notebook); fetchPost("/api/filetree/createDailyNote", { notebook, app: Constants.SIYUAN_APPID, diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 9fe3a3599..8ead248ec 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -271,7 +271,7 @@ const initBar = () => { notebook: item.id, app: Constants.SIYUAN_APPID, }); - window.localStorage.setItem(Constants.LOCAL_DAILYNOTEID, item.id); + localStorage.setItem(Constants.LOCAL_DAILYNOTEID, item.id); } }).element); }