From d7f09ff8f7e00915480de7a5130a3bef6b254e5f Mon Sep 17 00:00:00 2001 From: knowen <1369727119@qq.com> Date: Tue, 17 Mar 2026 22:31:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(gemini):=20=E6=B7=BB=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=89=80=E6=9C=89=E5=9B=BE=E7=89=87=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E6=9C=80=E6=96=B0=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gemini-ops.js | 53 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/gemini-ops.js b/src/gemini-ops.js index 3d11cdb..a1b4367 100644 --- a/src/gemini-ops.js +++ b/src/gemini-ops.js @@ -386,15 +386,61 @@ export function createOps(page) { }, /** - * 获取最新生成的图片信息 + * 获取本次会话中所有已加载的图片 + * + * 选择器逻辑: + * - img.image.loaded — 历史已加载图片(不带 animate) + * - img.image.animate.loaded — 最新生成的图片(带入场动画) + * 两者都匹配 img.image.loaded,所以用它拿全部。 + * + * @returns {Promise<{ok: boolean, images: Array<{src: string, alt: string, width: number, height: number, isNew: boolean, index: number}>, total: number, newCount: number, error?: string}>} */ - async getLatestImage() { + async getAllImages() { return op.query(() => { const imgs = [...document.querySelectorAll('img.image.loaded')]; if (!imgs.length) { + return { ok: false, images: [], total: 0, newCount: 0, error: 'no_loaded_images' }; + } + + const images = imgs.map((img, i) => ({ + src: img.src || '', + alt: img.alt || '', + width: img.naturalWidth || 0, + height: img.naturalHeight || 0, + isNew: img.classList.contains('animate'), + index: i, + })); + + const newCount = images.filter(i => i.isNew).length; + return { ok: true, images, total: images.length, newCount }; + }); + }, + + /** + * 获取最新生成的图片信息 + * + * 优先查找带 animate class 的图片(刚生成的), + * 如果没有则回退到最后一张已加载图片。 + * + * @returns {Promise<{ok: boolean, src?: string, alt?: string, width?: number, height?: number, isNew?: boolean, hasDownloadBtn?: boolean, error?: string}>} + */ + async getLatestImage() { + return op.query(() => { + // 优先:最新生成的图片(带 animate) + const newImgs = [...document.querySelectorAll('img.image.animate.loaded')]; + // 回退:所有已加载图片 + const allImgs = [...document.querySelectorAll('img.image.loaded')]; + + if (!allImgs.length) { return { ok: false, error: 'no_loaded_images' }; } - const img = imgs[imgs.length - 1]; + + // 取最新生成的最后一张,没有则取全部的最后一张 + const img = newImgs.length > 0 + ? newImgs[newImgs.length - 1] + : allImgs[allImgs.length - 1]; + const isNew = newImgs.length > 0 && newImgs[newImgs.length - 1] === img; + // 查找下载按钮 let container = img; while (container && container !== document.body) { @@ -412,6 +458,7 @@ export function createOps(page) { alt: img.alt || '', width: img.naturalWidth || 0, height: img.naturalHeight || 0, + isNew, hasDownloadBtn: !!dlBtn, }; });