From 448a88e11423d2850cfbba0c4e5dcab3657d867f Mon Sep 17 00:00:00 2001 From: Youzini-afk <13153778771cx@gmail.com> Date: Thu, 26 Mar 2026 15:20:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9D=A2=E6=9D=BF=E5=B0=BA=E5=AF=B8loc?= =?UTF-8?q?alStorage=E6=8C=81=E4=B9=85=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- panel.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/panel.js b/panel.js index efd223f..b2fe6da 100644 --- a/panel.js +++ b/panel.js @@ -195,6 +195,7 @@ export async function initPanel({ _bindTabs(); _bindClose(); _bindResizeHandle(); + _bindPanelResize(); _bindGraphControls(); _bindActions(); _bindConfigControls(); @@ -212,6 +213,8 @@ export function openPanel() { if (!overlayEl) return; overlayEl.classList.add("active"); + _restorePanelSize(); + const isMobile = _isMobile(); const settings = _getSettings?.() || {}; const themeName = settings.panelTheme || "crimson"; @@ -679,6 +682,40 @@ function _bindResizeHandle() { }); } +const PANEL_SIZE_KEY = "st-bme-panel-size"; +let _panelResizeTimer = null; + +function _bindPanelResize() { + if (!panelEl || typeof ResizeObserver === "undefined") return; + const observer = new ResizeObserver(() => { + clearTimeout(_panelResizeTimer); + _panelResizeTimer = setTimeout(() => { + if (!overlayEl?.classList.contains("active")) return; + const w = panelEl.offsetWidth; + const h = panelEl.offsetHeight; + if (w > 0 && h > 0) { + try { + localStorage.setItem(PANEL_SIZE_KEY, JSON.stringify({ w, h })); + } catch { /* ignore */ } + } + }, 300); + }); + observer.observe(panelEl); +} + +function _restorePanelSize() { + if (!panelEl) return; + try { + const raw = localStorage.getItem(PANEL_SIZE_KEY); + if (!raw) return; + const { w, h } = JSON.parse(raw); + if (Number.isFinite(w) && Number.isFinite(h) && w > 200 && h > 200) { + panelEl.style.width = w + "px"; + panelEl.style.height = h + "px"; + } + } catch { /* ignore */ } +} + // ==================== 操作绑定 ==================== function _bindActions() {