From 620c3c7cc24b0181ba2d9c0bef620ad9193e2eae Mon Sep 17 00:00:00 2001 From: XPoet Date: Tue, 1 Sep 2020 18:37:00 +0800 Subject: [PATCH] refactor: modified localStorage Key for light/night toggle --- source/js/toggle-mode.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/js/toggle-mode.js b/source/js/toggle-mode.js index b344dfe..9d09bff 100644 --- a/source/js/toggle-mode.js +++ b/source/js/toggle-mode.js @@ -1,11 +1,11 @@ /** * 日间/夜间 模式切换 */ +const localStorageKey = 'MAGIC' const modeToggleBtn = document.querySelector('.mode-toggle'); const iconDom = modeToggleBtn.querySelector('i'); -// const articleContent = document.querySelector('.article-content'); const articleContent = document.querySelector('.main-content'); -const modeConfig = JSON.parse(localStorage.getItem('ils_x')); +const modeConfig = JSON.parse(localStorage.getItem(localStorageKey)); if (modeConfig) { if (modeConfig.prefersColorScheme === 'dark') { @@ -47,7 +47,7 @@ const setItemUtil = (modeClass, prefersColorScheme) => { iconDom.className = 'fa fa-lightbulb-o'; articleContent.classList.add('night-code-theme'); } - localStorage.setItem('ils_x', JSON.stringify( + localStorage.setItem(localStorageKey, JSON.stringify( { prefersColorScheme: prefersColorScheme, isDark: isDark @@ -67,4 +67,4 @@ modeToggleBtn.addEventListener('click', function (e) { setItemUtil('dark-mode', 'light'); } -}); \ No newline at end of file +});