From 2f988808b2e8ee94c7bc26b09c4df8f50c127dbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Wed, 18 Feb 2026 22:26:34 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E6=89=93=E5=BC=80=E9=A1=B5=E9=9D=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/service_worker/gm_api/gm_api.ts | 19 +++++++++++++++++++ src/app/service/service_worker/index.ts | 7 +++++-- src/app/service/service_worker/subscribe.ts | 3 ++- src/app/service/service_worker/synchronize.ts | 3 ++- src/app/service/service_worker/utils.ts | 18 ++++++++++++++++++ src/pkg/utils/utils.ts | 9 --------- 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/app/service/service_worker/gm_api/gm_api.ts b/src/app/service/service_worker/gm_api/gm_api.ts index c4593f350..05fa47fa0 100644 --- a/src/app/service/service_worker/gm_api/gm_api.ts +++ b/src/app/service/service_worker/gm_api/gm_api.ts @@ -26,6 +26,7 @@ import type { GMApiRequest, } from "../types"; import type { TScriptMenuRegister, TScriptMenuUnregister } from "../../queue"; +import type { NotificationOptionCache } from "../utils"; import { BrowserNoSupport, notificationsUpdate } from "../utils"; import i18n from "@App/locales/locales"; import { encodeRValue, type TKeyValuePair } from "@App/pkg/utils/message_value"; @@ -1320,6 +1321,24 @@ export default class GMApi { params, } as NotificationMessageOption, }); + } else { + // 从缓存中检查是不是有选项 + const options = await cacheInstance.get(`notification:${notificationId}:options`); + if (options) { + if (event === "click") { + if (options.url) { + // 打开链接 + chrome.tabs.create({ + url: options.url, + }); + // 关闭通知 + chrome.notifications.clear(notificationId); + } + } else if (event === "close") { + // 删除缓存 + cacheInstance.del(`notification:${notificationId}:options`); + } + } } }; chrome.notifications.onClosed.addListener((notificationId, byUser) => { diff --git a/src/app/service/service_worker/index.ts b/src/app/service/service_worker/index.ts index 7dde2ece5..51f381283 100644 --- a/src/app/service/service_worker/index.ts +++ b/src/app/service/service_worker/index.ts @@ -14,12 +14,13 @@ import { ScriptDAO } from "@App/app/repo/scripts"; import { SystemService } from "./system"; import { type Logger, LoggerDAO } from "@App/app/repo/logger"; import { initLocales, initLocalesPromise, localePath, t, watchLanguageChange } from "@App/locales/locales"; -import { getCurrentTab, InfoNotification } from "@App/pkg/utils/utils"; +import { getCurrentTab } from "@App/pkg/utils/utils"; import { onTabRemoved, onUrlNavigated, setOnUserActionDomainChanged } from "./url_monitor"; import { LocalStorageDAO } from "@App/app/repo/localStorage"; import { FaviconDAO } from "@App/app/repo/favicon"; import { onRegularUpdateCheckAlarm } from "./regular_updatecheck"; import { cacheInstance } from "@App/app/cache"; +import { InfoNotification } from "./utils"; // service worker的管理器 export default class ServiceWorkerManager { @@ -207,7 +208,9 @@ export default class ServiceWorkerManager { const url = `${DocumentationSite}${localePath}/docs/change/${ExtVersion.includes("-") ? "beta-changelog/" : ""}#${ExtVersion}`; // 如果只是修复版本,只弹出通知不打开页面 // beta版本还是每次都打开更新页面 - InfoNotification(t("ext_update_notification"), t("ext_update_notification_desc", { version: ExtVersion })); + InfoNotification(t("ext_update_notification"), t("ext_update_notification_desc", { version: ExtVersion }), { + url, + }); if (ExtVersion.endsWith(".0")) { getCurrentTab() .then((tab) => { diff --git a/src/app/service/service_worker/subscribe.ts b/src/app/service/service_worker/subscribe.ts index 7062c5565..5ec19875a 100644 --- a/src/app/service/service_worker/subscribe.ts +++ b/src/app/service/service_worker/subscribe.ts @@ -9,13 +9,14 @@ import { type Group } from "@Packages/message/server"; import { type ScriptService } from "./script"; import { createScriptInfo, type InstallSource } from "@App/pkg/utils/scriptInstall"; import { type TInstallSubscribe } from "../queue"; -import { checkSilenceUpdate, InfoNotification } from "@App/pkg/utils/utils"; +import { checkSilenceUpdate } from "@App/pkg/utils/utils"; import { ltever } from "@App/pkg/utils/semver"; import { fetchScriptBody, parseMetadata, prepareSubscribeByCode } from "@App/pkg/utils/script"; import { cacheInstance } from "@App/app/cache"; import { uuidv4 } from "@App/pkg/utils/uuid"; import { CACHE_KEY_SCRIPT_INFO } from "@App/app/cache_key"; import i18n, { i18nName } from "@App/locales/locales"; +import { InfoNotification } from "./utils"; export class SubscribeService { logger: Logger; diff --git a/src/app/service/service_worker/synchronize.ts b/src/app/service/service_worker/synchronize.ts index c29ce2d1b..9d2c00a7f 100644 --- a/src/app/service/service_worker/synchronize.ts +++ b/src/app/service/service_worker/synchronize.ts @@ -24,7 +24,7 @@ import { type ResourceService } from "./resource"; import { createObjectURL } from "../offscreen/client"; import { type CloudSyncConfig, type SystemConfig } from "@App/pkg/config/config"; import type { TDeleteScript, TInstallScript, TInstallScriptParams } from "../queue"; -import { errorMsg, InfoNotification, makeBlobURL } from "@App/pkg/utils/utils"; +import { errorMsg, makeBlobURL } from "@App/pkg/utils/utils"; import { t } from "i18next"; import ChromeStorage from "@App/pkg/config/chrome_storage"; import { type ScriptService } from "./script"; @@ -32,6 +32,7 @@ import { prepareScriptByCode } from "@App/pkg/utils/script"; import { ExtVersion } from "@App/app/const"; import { dayFormat } from "@App/pkg/utils/day_format"; import i18n, { i18nName } from "@App/locales/locales"; +import { InfoNotification } from "./utils"; // type SynchronizeTarget = "local"; diff --git a/src/app/service/service_worker/utils.ts b/src/app/service/service_worker/utils.ts index 9e7adfeba..17bea5e1c 100644 --- a/src/app/service/service_worker/utils.ts +++ b/src/app/service/service_worker/utils.ts @@ -17,6 +17,7 @@ import { toUniquePatternStrings, type URLRuleEntry, } from "@App/pkg/utils/url_matcher"; +import { cacheInstance } from "@App/app/cache"; export function getRunAt(runAts: string[]): chrome.extensionTypes.RunAt { // 没有 run-at 时为 undefined. Fallback 至 document_idle @@ -287,3 +288,20 @@ export const removeFavicon = (filename: string): Promise => { .then((opfsRoot) => opfsRoot.getDirectoryHandle(`cached_favicons`)) .then((faviconsFolder) => faviconsFolder.removeEntry(`${filename}`, { recursive: true })); }; + +export type NotificationOptionCache = { + url?: string; +}; + +export async function InfoNotification(title: string, msg: string, options?: NotificationOptionCache) { + const notificationId = await chrome.notifications.create({ + type: "basic", + title, + message: msg, + iconUrl: chrome.runtime.getURL("assets/logo.png"), + }); + // 如果设定了url,则保存到cache里,在gm_api中集中处理 + if (options) { + cacheInstance.set(`notification:${notificationId}:options`, options); + } +} diff --git a/src/pkg/utils/utils.ts b/src/pkg/utils/utils.ts index 9b9ff2fe4..8ffa32941 100644 --- a/src/pkg/utils/utils.ts +++ b/src/pkg/utils/utils.ts @@ -44,15 +44,6 @@ export function isFirefox() { return typeof mozInnerScreenX !== "undefined"; } -export function InfoNotification(title: string, msg: string) { - chrome.notifications.create({ - type: "basic", - title, - message: msg, - iconUrl: chrome.runtime.getURL("assets/logo.png"), - }); -} - export function valueType(val: unknown) { switch (typeof val) { case "string": From 7ca57bb7d94ae47bde3d2e64f8a207bfda629700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Wed, 18 Feb 2026 22:28:34 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/service/service_worker/gm_api/gm_api.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/service/service_worker/gm_api/gm_api.ts b/src/app/service/service_worker/gm_api/gm_api.ts index 05fa47fa0..e2c544a9b 100644 --- a/src/app/service/service_worker/gm_api/gm_api.ts +++ b/src/app/service/service_worker/gm_api/gm_api.ts @@ -1333,6 +1333,7 @@ export default class GMApi { }); // 关闭通知 chrome.notifications.clear(notificationId); + cacheInstance.del(`notification:${notificationId}:options`); } } else if (event === "close") { // 删除缓存 From 84064b753cc310e097354ce984efad44ca582134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=B8=80=E4=B9=8B?= Date: Wed, 18 Feb 2026 22:30:22 +0800 Subject: [PATCH 3/3] 1.3.0-beta.4 --- package.json | 2 +- src/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 67aa9f829..fb3929cee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scriptcat", - "version": "1.3.0-beta.3", + "version": "1.3.0-beta.4", "description": "脚本猫,一个可以执行用户脚本的浏览器扩展,万物皆可脚本化,让你的浏览器可以做更多的事情!", "author": "CodFrm", "license": "GPLv3", diff --git a/src/manifest.json b/src/manifest.json index b0ef98365..e33573b9a 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "__MSG_scriptcat__", - "version": "1.3.0.1400", + "version": "1.3.0.1500", "author": "CodFrm", "description": "__MSG_scriptcat_description__", "options_ui": {