-
Notifications
You must be signed in to change notification settings - Fork 336
不依赖外部网站访问进行安装 + 安装页版面调整 #842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 23 commits
29c949c
d5f6310
404daa7
49ccdb4
8e00da0
d5dd55f
984b571
59ba067
031d412
d95d5b4
f6ebfb9
aac9f3f
d8ff8fd
694177b
1d5db72
cd8fae0
ebd6a4f
9eca6c4
9fe2303
ace4c07
fde4eac
e0375eb
55cf73f
5b8b1fb
350b592
d075143
b8631e2
4e31818
121e737
a22e03c
b844d56
d18b9cb
33383ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,9 +28,7 @@ import { type ResourceService } from "./resource"; | |||||||||||||||||||||||||||||
| import { type ValueService } from "./value"; | ||||||||||||||||||||||||||||||
| import { compileScriptCode } from "../content/utils"; | ||||||||||||||||||||||||||||||
| import { type SystemConfig } from "@App/pkg/config/config"; | ||||||||||||||||||||||||||||||
| import { localePath, watchLanguageChange } from "@App/locales/locales"; | ||||||||||||||||||||||||||||||
| import { arrayMove } from "@dnd-kit/sortable"; | ||||||||||||||||||||||||||||||
| import { DocumentationSite } from "@App/app/const"; | ||||||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||||||
| TScriptRunStatus, | ||||||||||||||||||||||||||||||
| TDeleteScript, | ||||||||||||||||||||||||||||||
|
|
@@ -39,7 +37,6 @@ import type { | |||||||||||||||||||||||||||||
| TSortedScript, | ||||||||||||||||||||||||||||||
| TInstallScriptParams, | ||||||||||||||||||||||||||||||
| } from "../queue"; | ||||||||||||||||||||||||||||||
| import { timeoutExecution } from "@App/pkg/utils/timer"; | ||||||||||||||||||||||||||||||
| import { buildScriptRunResourceBasic, selfMetadataUpdate } from "./utils"; | ||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||
| BatchUpdateListActionCode, | ||||||||||||||||||||||||||||||
|
|
@@ -54,8 +51,6 @@ import { CompiledResourceDAO } from "@App/app/repo/resource"; | |||||||||||||||||||||||||||||
| import { initRegularUpdateCheck } from "./regular_updatecheck"; | ||||||||||||||||||||||||||||||
| // import { gzip as pakoGzip } from "pako"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| const cIdKey = `(cid_${Math.random()})`; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export type TCheckScriptUpdateOption = Partial< | ||||||||||||||||||||||||||||||
| { checkType: "user"; noUpdateCheck?: number } | ({ checkType: "system" } & Record<string, any>) | ||||||||||||||||||||||||||||||
| >; | ||||||||||||||||||||||||||||||
|
|
@@ -84,13 +79,14 @@ export class ScriptService { | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| listenerScriptInstall() { | ||||||||||||||||||||||||||||||
| // 初始化脚本安装监听 | ||||||||||||||||||||||||||||||
| chrome.webRequest.onBeforeRequest.addListener( | ||||||||||||||||||||||||||||||
| (req: chrome.webRequest.OnBeforeRequestDetails) => { | ||||||||||||||||||||||||||||||
| // 处理url, 实现安装脚本 | ||||||||||||||||||||||||||||||
| if (req.method !== "GET") { | ||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||
| chrome.webNavigation.onBeforeNavigate.addListener( | ||||||||||||||||||||||||||||||
| (req: chrome.webNavigation.WebNavigationBaseCallbackDetails) => { | ||||||||||||||||||||||||||||||
| const lastError = chrome.runtime.lastError; | ||||||||||||||||||||||||||||||
| if (lastError) { | ||||||||||||||||||||||||||||||
| console.error(lastError.message); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| let targetUrl: string | null = null; | ||||||||||||||||||||||||||||||
| // 处理url, 实现安装脚本 | ||||||||||||||||||||||||||||||
| let targetUrl: string; | ||||||||||||||||||||||||||||||
| // 判断是否为 file:///*/*.user.js | ||||||||||||||||||||||||||||||
| if (req.url.startsWith("file://") && req.url.endsWith(".user.js")) { | ||||||||||||||||||||||||||||||
| targetUrl = req.url; | ||||||||||||||||||||||||||||||
|
|
@@ -101,11 +97,12 @@ export class ScriptService { | |||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| // 判断是否有url参数 | ||||||||||||||||||||||||||||||
| if (!reqUrl.hash.includes("url=")) { | ||||||||||||||||||||||||||||||
| const idx = reqUrl.hash.indexOf("url="); | ||||||||||||||||||||||||||||||
| if (idx < 0) { | ||||||||||||||||||||||||||||||
| return undefined; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| // 获取url参数 | ||||||||||||||||||||||||||||||
| targetUrl = reqUrl.hash.split("url=")[1]; | ||||||||||||||||||||||||||||||
| targetUrl = reqUrl.hash.substring(idx + 4); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| // 读取脚本url内容, 进行安装 | ||||||||||||||||||||||||||||||
| const logger = this.logger.with({ url: targetUrl }); | ||||||||||||||||||||||||||||||
|
|
@@ -153,15 +150,30 @@ export class ScriptService { | |||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| urls: [ | ||||||||||||||||||||||||||||||
| `${DocumentationSite}/docs/script_installation/*`, | ||||||||||||||||||||||||||||||
| `${DocumentationSite}/en/docs/script_installation/*`, | ||||||||||||||||||||||||||||||
| "https://www.tampermonkey.net/script_installation.php*", | ||||||||||||||||||||||||||||||
| "file:///*/*.user.js*", | ||||||||||||||||||||||||||||||
| url: [ | ||||||||||||||||||||||||||||||
| { schemes: ["http", "https"], hostEquals: "docs.scriptcat.org", pathPrefix: "/docs/script_installation/" }, | ||||||||||||||||||||||||||||||
| { schemes: ["http", "https"], hostEquals: "docs.scriptcat.org", pathPrefix: "/en/docs/script_installation/" }, | ||||||||||||||||||||||||||||||
| { schemes: ["http", "https"], hostEquals: "www.tampermonkey.net", pathPrefix: "/script_installation.php" }, | ||||||||||||||||||||||||||||||
| { schemes: ["file"], pathSuffix: ".user.js" }, | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| types: ["main_frame"], | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // chrome.webRequest.onHeadersReceived.addListener( | ||||||||||||||||||||||||||||||
| // (details) => { | ||||||||||||||||||||||||||||||
| // const lastError = chrome.runtime.lastError; | ||||||||||||||||||||||||||||||
| // if (lastError) { | ||||||||||||||||||||||||||||||
| // console.error(lastError.message); | ||||||||||||||||||||||||||||||
| // } | ||||||||||||||||||||||||||||||
| // console.log("onHeadersReceived inspect", details); | ||||||||||||||||||||||||||||||
| // return undefined; | ||||||||||||||||||||||||||||||
| // }, | ||||||||||||||||||||||||||||||
| // { | ||||||||||||||||||||||||||||||
| // urls: ["*://*/*.user.js", "*://*/*.user.bg.js", "*://*/*.user.sub.js"], | ||||||||||||||||||||||||||||||
| // }, | ||||||||||||||||||||||||||||||
| // ["responseHeaders"] | ||||||||||||||||||||||||||||||
| // ); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| // chrome.webRequest.onHeadersReceived.addListener( | |
| // (details) => { | |
| // const lastError = chrome.runtime.lastError; | |
| // if (lastError) { | |
| // console.error(lastError.message); | |
| // } | |
| // console.log("onHeadersReceived inspect", details); | |
| // return undefined; | |
| // }, | |
| // { | |
| // urls: ["*://*/*.user.js", "*://*/*.user.bg.js", "*://*/*.user.sub.js"], | |
| // }, | |
| // ["responseHeaders"] | |
| // ); |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在listenerScriptInstall方法中,chrome.runtime.getURL("src/install.html")在每次方法调用时都会执行。由于这个URL在扩展的生命周期内是不变的,建议将其移到类的构造函数或作为类的静态属性,避免重复计算。
例如:
private readonly installPageURL: string;
constructor(...) {
// ...
this.installPageURL = chrome.runtime.getURL("src/install.html");
}| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -281,7 +281,8 @@ | |||||
| "script_requires": "Скрипт ссылается на следующие внешние ресурсы", | ||||||
| "cookie_warning": "Обратите внимание, что этот скрипт запрашивает разрешения на операции с Cookie. Это опасное разрешение, пожалуйста, убедитесь в безопасности скрипта.", | ||||||
| "scheduled_script_description_title": "Это запланированный скрипт. После включения он будет автоматически выполняться в определенное время и может управляться вручную с панели.", | ||||||
| "scheduled_script_description_description": "Выражение планировщика: {{expression}}, последнее время выполнения: {{time}}", | ||||||
| "scheduled_script_description_description_expr": "Выражение планировщика", | ||||||
|
||||||
| "scheduled_script_description_description_expr": "Выражение планировщика", | |
| "scheduled_script_description_description_expr": "Выражение планировщика:", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
webNavigation.onBeforeNavigate监听器中检查chrome.runtime.lastError的时机不正确。chrome.runtime.lastError应该在异步API的回调函数中检查,而不是在事件监听器的开始。在这个上下文中,
lastError应该总是undefined,因为这里没有进行任何Chrome API调用。建议删除这段代码:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
什麼鬼?