From eb4f50ea9244cb3b9df5d9a54982a158c8c0340b Mon Sep 17 00:00:00 2001 From: cyfung1031 <44498510+cyfung1031@users.noreply.github.com> Date: Mon, 20 Oct 2025 19:00:42 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E5=BC=83=E6=8E=89=20`GM=5FopenInTab({=20us?= =?UTF-8?q?eOpen:=20true=20})`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/service/offscreen/gm_api.ts | 5 -- src/app/service/service_worker/gm_api.ts | 92 ++++++++++-------------- src/template/scriptcat.d.tpl | 6 +- src/types/scriptcat.d.ts | 6 +- 4 files changed, 43 insertions(+), 66 deletions(-) diff --git a/src/app/service/offscreen/gm_api.ts b/src/app/service/offscreen/gm_api.ts index d63f105f6..b397fc918 100644 --- a/src/app/service/offscreen/gm_api.ts +++ b/src/app/service/offscreen/gm_api.ts @@ -179,10 +179,6 @@ export default class GMApi { }); } - async openInTab({ url }: { url: string }) { - return window.open(url) !== undefined; - } - textarea: HTMLTextAreaElement = document.createElement("textarea"); clipboardData: { type?: string; data: string } | undefined; @@ -210,7 +206,6 @@ export default class GMApi { }); this.group.on("xmlHttpRequest", this.xmlHttpRequest.bind(this)); - this.group.on("openInTab", this.openInTab.bind(this)); this.group.on("setClipboard", this.setClipboard.bind(this)); } } diff --git a/src/app/service/service_worker/gm_api.ts b/src/app/service/service_worker/gm_api.ts index 5e1e22e44..f39059228 100644 --- a/src/app/service/service_worker/gm_api.ts +++ b/src/app/service/service_worker/gm_api.ts @@ -852,61 +852,47 @@ export default class GMApi { const url = request.params[0]; const options = request.params[1]; const getNewTabId = async () => { - if (options.useOpen === true) { - // 发送给offscreen页面处理 (使用window.open) - const ok = await sendMessage(this.msgSender, "offscreen/gmApi/openInTab", { url }); - if (ok) { - // 由于window.open强制在前台打开标签,因此获取状态为{ active:true }的标签即为新标签 - const tab = await getCurrentTab(); - return tab.id; - } else { - // 当新tab被浏览器阻止时window.open()会返回null 视为已经关闭 - // 似乎在Firefox中禁止在background页面使用window.open(),强制返回null - return false; - } - } else { - const { tabId, windowId } = sender.getExtMessageSender(); - const active = options.active; - const currentTab = await chrome.tabs.get(tabId); - let newTabIndex = -1; - if (options.incognito && !currentTab.incognito) { - // incognito: "split" 在 normal 里不会看到 incognito - // 只能创建新 incognito window - // pinned 无效 - // insert 不重要 - await chrome.windows.create({ - url, - incognito: true, - focused: active, - }); - return 0; - } - if ((typeof options.insert === "number" || options.insert === true) && currentTab && currentTab.index >= 0) { - // insert 为 boolean 时,插入至当前Tab下一格 (TM行为) - // insert 为 number 时,插入至相对位置 (SC独自) - const insert = +options.insert; - newTabIndex = currentTab.index + insert; - if (newTabIndex < 0) newTabIndex = 0; - } - const createProperties = { + const { tabId, windowId } = sender.getExtMessageSender(); + const active = options.active; + const currentTab = await chrome.tabs.get(tabId); + let newTabIndex = -1; + if (options.incognito && !currentTab.incognito) { + // incognito: "split" 在 normal 里不会看到 incognito + // 只能创建新 incognito window + // pinned 无效 + // insert 不重要 + await chrome.windows.create({ url, - active: active, - } as chrome.tabs.CreateProperties; - if (options.setParent) { - // SC 预设 setParent: true 以避免不可预计的问题 - createProperties.openerTabId = tabId === -1 ? undefined : tabId; - createProperties.windowId = windowId === -1 ? undefined : windowId; - } - if (options.pinned) { - // VM/FM行为 - createProperties.pinned = true; - } else if (newTabIndex >= 0) { - // insert option; pinned 情况下无效 - createProperties.index = newTabIndex; - } - const tab = await chrome.tabs.create(createProperties); - return tab.id; + incognito: true, + focused: active, + }); + return 0; + } + if ((typeof options.insert === "number" || options.insert === true) && currentTab && currentTab.index >= 0) { + // insert 为 boolean 时,插入至当前Tab下一格 (TM行为) + // insert 为 number 时,插入至相对位置 (SC独自) + const insert = +options.insert; + newTabIndex = currentTab.index + insert; + if (newTabIndex < 0) newTabIndex = 0; + } + const createProperties = { + url, + active: active, + } as chrome.tabs.CreateProperties; + if (options.setParent) { + // SC 预设 setParent: true 以避免不可预计的问题 + createProperties.openerTabId = tabId === -1 ? undefined : tabId; + createProperties.windowId = windowId === -1 ? undefined : windowId; + } + if (options.pinned) { + // VM/FM行为 + createProperties.pinned = true; + } else if (newTabIndex >= 0) { + // insert option; pinned 情况下无效 + createProperties.index = newTabIndex; } + const tab = await chrome.tabs.create(createProperties); + return tab.id; }; const tabId = await getNewTabId(); if (tabId) { diff --git a/src/template/scriptcat.d.tpl b/src/template/scriptcat.d.tpl index 37e6aa811..e0f51f98c 100644 --- a/src/template/scriptcat.d.tpl +++ b/src/template/scriptcat.d.tpl @@ -456,13 +456,11 @@ declare namespace GMTypes { pinned?: boolean; /** - * 使用 `window.open` 打开新窗口,而不是浏览器 API。 - * 可以打开某些特殊的链接 + * 【弃用参数】本来用于打开本地特殊协定链接。升级MV3版后已完全不需使用。 * * 相关:Issue #178 - * 默认值:false */ - useOpen?: boolean; + useOpen?: never; } interface XHRResponse { diff --git a/src/types/scriptcat.d.ts b/src/types/scriptcat.d.ts index b94abb737..1d91287e4 100644 --- a/src/types/scriptcat.d.ts +++ b/src/types/scriptcat.d.ts @@ -464,13 +464,11 @@ declare namespace GMTypes { pinned?: boolean; /** - * 使用 `window.open` 打开新窗口,而不是浏览器 API。 - * 可以打开某些特殊的链接 + * 【弃用参数】本来用于打开本地特殊协定链接。升级MV3版后已完全不需使用。 * * 相关:Issue #178 - * 默认值:false */ - useOpen?: boolean; + useOpen?: never; } type SWOpenTabOptions = OpenTabOptions & Required>; From d9a3bf49a819729c4a69a222d2df3fdec111096f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Tue, 21 Oct 2025 15:52:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A4=84=E7=90=86lint=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=92=8C=E5=88=A0=E9=99=A4=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/service/service_worker/gm_api.ts | 2 +- src/template/scriptcat.d.tpl | 19 ++++++++++++------- src/types/scriptcat.d.ts | 7 ------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/app/service/service_worker/gm_api.ts b/src/app/service/service_worker/gm_api.ts index f39059228..f76e9f6ca 100644 --- a/src/app/service/service_worker/gm_api.ts +++ b/src/app/service/service_worker/gm_api.ts @@ -12,7 +12,7 @@ import PermissionVerify, { PermissionVerifyApiGet } from "./permission_verify"; import { cacheInstance } from "@App/app/cache"; import EventEmitter from "eventemitter3"; import { type RuntimeService } from "./runtime"; -import { getIcon, isFirefox, getCurrentTab, openInCurrentTab, cleanFileName } from "@App/pkg/utils/utils"; +import { getIcon, isFirefox, openInCurrentTab, cleanFileName } from "@App/pkg/utils/utils"; import { type SystemConfig } from "@App/pkg/config/config"; import i18next, { i18nName } from "@App/locales/locales"; import FileSystemFactory from "@Packages/filesystem/factory"; diff --git a/src/template/scriptcat.d.tpl b/src/template/scriptcat.d.tpl index e0f51f98c..71557a284 100644 --- a/src/template/scriptcat.d.tpl +++ b/src/template/scriptcat.d.tpl @@ -335,6 +335,14 @@ declare namespace CATType { // 文件修改时间 updatetime: number; } + + type CATFileStorageDetails = { + baseDir: string; + path: string; + filename: any; + file: FileStorageFileInfo; + data?: string; + }; } declare namespace GMTypes { @@ -454,15 +462,10 @@ declare namespace GMTypes { * 默认值:false */ pinned?: boolean; - - /** - * 【弃用参数】本来用于打开本地特殊协定链接。升级MV3版后已完全不需使用。 - * - * 相关:Issue #178 - */ - useOpen?: never; } + type SWOpenTabOptions = OpenTabOptions & Required>; + interface XHRResponse { finalUrl?: string; readyState?: 0 | 1 | 2 | 3 | 4; @@ -592,4 +595,6 @@ declare namespace GMTypes { closed?: boolean; name?: string; } + + type GMClipboardInfo = string | { type?: string; mimetype?: string }; } diff --git a/src/types/scriptcat.d.ts b/src/types/scriptcat.d.ts index 1d91287e4..71557a284 100644 --- a/src/types/scriptcat.d.ts +++ b/src/types/scriptcat.d.ts @@ -462,13 +462,6 @@ declare namespace GMTypes { * 默认值:false */ pinned?: boolean; - - /** - * 【弃用参数】本来用于打开本地特殊协定链接。升级MV3版后已完全不需使用。 - * - * 相关:Issue #178 - */ - useOpen?: never; } type SWOpenTabOptions = OpenTabOptions & Required>;