From 33147c3610a3264d2e98b4519ecf98d1bb092de0 Mon Sep 17 00:00:00 2001 From: WJZ_P <110795301+WJZ-P@users.noreply.github.com> Date: Tue, 17 Mar 2026 00:10:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(gemini-ops):=20=E6=B7=BB=E5=8A=A0=E4=BE=A7?= =?UTF-8?q?=E8=BE=B9=E6=A0=8F=E5=B1=95=E5=BC=80=E7=8A=B6=E6=80=81=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gemini-ops.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/gemini-ops.js b/src/gemini-ops.js index 51795bb..005370b 100644 --- a/src/gemini-ops.js +++ b/src/gemini-ops.js @@ -36,6 +36,10 @@ const SELECTORS = { 'button.temp-chat-button', // class 名兜底 'button[mattooltip="临时对话"]', // Angular Material tooltip 属性 ], + sidebarContainer: [ + '[data-test-id="overflow-container"]', // 测试专属属性 + 'div.overflow-container', // class 兜底 + ], }; /** @@ -387,6 +391,31 @@ export function createOps(page) { }; } +/** + * 判断侧边栏是否处于展开状态(内部工具函数,不对外暴露) + * + * 通过 overflow-container 元素的实际渲染宽度判断: + * - width >= 100px → 展开 + * - width < 100px → 折叠 + * + * @param {ReturnType} op + * @returns {Promise<{ok: boolean, expanded: boolean, width: number, error?: string}>} + */ +function isSidebarExpanded(op) { + return op.query((sels) => { + let el = null; + for (const sel of sels) { + try { el = document.querySelector(sel); } catch { /* skip */ } + if (el) break; + } + if (!el) { + return { ok: false, expanded: false, width: 0, error: 'sidebar_container_not_found' }; + } + const width = el.getBoundingClientRect().width; + return { ok: true, expanded: width >= 100, width }; + }, SELECTORS.sidebarContainer); +} + function sleep(ms) { return new Promise(r => setTimeout(r, ms)); }