-
Notifications
You must be signed in to change notification settings - Fork 298
整理 inject & content,修改 pageLoad 资讯量传递 #952
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
Conversation
ef9f0f2 to
0866918
Compare
0866918 to
cf0d22c
Compare
|
看起来修了这个就可以发下一个beta版本了,怎么变draft了 |
|
@CodFrm 改好了。 之前的 一些写法也改了一下 |
没打算合并 #951 和 #950 到v1.2,只是刚好看到了,疑问怎么不合并到 main 或者 release/v1.3,合并到 develop/raw-message ,然后 develop/raw-message 又有一个pr #949,这样的话,commit message就乱了,你后续在 #949 (comment) 说的,我觉得才是合理的方法,我晚些整理一下 现在尽量少一些改动,只做fix,然后发布v1.2,其它的都可以是v1.3的内容 |
|
@CodFrm 这个会合并到 1.2 吗? 还是要先折开? |
合吧,要合的我都标记hotfix |
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.
Pull Request Overview
这个 PR 主要进行了架构重构,优化了 inject 和 content 环境之间的消息传递机制,并减少了页面加载时传输的数据量。主要变更包括将 MessageFlags 对象简化为 MessageFlag 字符串,引入 TScriptInfo 类型以减少传输的脚本信息,以及重构 pageLoad 流程以更清晰地分离不同环境的脚本数据。
主要变更:
- 将
MessageFlags接口简化为MessageFlag字符串类型,减少不必要的对象包装 - 引入
TScriptInfo类型和trimScriptInfo函数,在传递给 inject/content 环境时删除不必要的脚本元数据 - 重构
pageLoad方法,将脚本列表分为injectScriptList和contentScriptList,并优化返回结构
Reviewed Changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types/main.d.ts | 添加 Override 工具类型,将 MessageFlags 接口简化为 MessageFlag 字符串常量 |
| src/pkg/utils/utils.ts | 扩展 getStorageName 函数以支持 TScriptInfo 类型 |
| src/manifest.json | 版本号从 1.2.0.1500 更新到 1.2.0.1600 |
| src/inject.ts | 更新为使用新的 MessageFlag 字符串和重构后的 pageLoad 数据结构 |
| src/content.ts | 更新为使用新的 MessageFlag 字符串 |
| src/app/service/service_worker/utils.ts | 更新 compileInjectionCode 参数类型从 MessageFlags 到字符串 |
| src/app/service/service_worker/types.ts | 将 ScriptLoadInfo 接口移动到 scripts.ts,并重新导出 |
| src/app/service/service_worker/runtime.ts | 重构 pageLoad 方法,添加 getScriptsForTab 方法,引入 USERSCRIPTS_REGISTER_CONTROL 常量 |
| src/app/service/service_worker/popup_scriptmenu.ts | 新文件:提取 scriptToMenu 函数和 TPopupPageLoadInfo 类型定义 |
| src/app/service/service_worker/popup.ts | 使用提取的 scriptToMenu 函数,更新 pageLoad 事件订阅为 popupPageLoadUpdate |
| src/app/service/service_worker/client.ts | 更新 pageLoad 方法返回类型为 TClientPageLoadInfo |
| src/app/service/content/utils.ts | 添加 trimScriptInfo 函数以减少传输数据,重构 compilePreInjectScript 以通过 CustomEvent 传递 scriptInfo |
| src/app/service/content/types.ts | 删除 PreScriptFunc 类型定义 |
| src/app/service/content/script_executor.ts | 重命名 init 为 setEnvInfo,start 为 startScripts,更新 execEarlyScript 以接收 scriptInfo 参数 |
| src/app/service/content/inject.ts | 拆分 init 方法,添加 setEnvInfo、startScripts 和 onInjectPageLoaded 方法 |
| src/app/service/content/gm_api/gm_info.ts | 更新 evaluateGMInfo 参数类型为 TScriptInfo,改进 scriptWillUpdate 逻辑 |
| src/app/service/content/exec_script.ts | 更新 scriptRes 类型为 TScriptInfo |
| src/app/service/content/create_context.ts | 更新 scriptRes 参数类型为 TScriptInfo |
| src/app/service/content/content.ts | 重构 pageLoad 和 start 方法,使用 Set 替代 Map 存储 content 脚本 |
| src/app/repo/scripts.ts | 添加 ScriptLoadInfo、TScriptInfo 和 TClientPageLoadInfo 类型定义 |
| packages/message/server.test.ts | 更新测试以使用字符串类型的 flags |
| packages/message/custom_event_message.ts | 简化构造函数参数,直接接收 messageFlag 字符串 |
| package.json | 版本号从 1.2.0-beta.4 更新到 1.2.0-beta.5 |
| // 发布给 Popup 的资讯 | ||
| const scriptmenus = enableScriptList.map((script) => scriptToMenu(script)); | ||
|
|
||
| let domain = ""; | ||
| try { | ||
| const url = chromeSender.url ? new URL(chromeSender.url) : null; | ||
| if (url?.protocol?.startsWith("http")) { | ||
| domain = url.hostname; | ||
| const u = url ? new URL(url) : null; | ||
| if (u?.protocol?.startsWith("http")) { | ||
| domain = u.hostname; | ||
| } | ||
| } catch { | ||
| // ignore | ||
| } | ||
| if (domain) { | ||
| for (const script of enableScript) { | ||
| for (const script of enableScriptList) { | ||
| this.sitesLoaded.add(`${script.uuid}|${domain}`); | ||
| } | ||
| Promise.resolve().then(() => this.updateSites()); | ||
| } | ||
|
|
||
| const injectScriptList: TScriptInfo[] = []; | ||
| const contentScriptList: TScriptInfo[] = []; | ||
| for (const script of enableScriptList) { | ||
| const list = isInjectIntoContent(script.metadata) ? contentScriptList : injectScriptList; | ||
| list.push(trimScriptInfo({ ...script })); | ||
| } | ||
|
|
||
| // 发布给 inject 和 content 的资讯 |
Copilot
AI
Nov 16, 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.
注释中的"資讯"和"資料"使用了繁体中文字符,而项目的其他注释主要使用简体中文。为了保持一致性,建议将这些注释改为简体中文:"发布给 Popup 的资讯"和"发布给 inject 和 content 的资讯"。
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.
简体中文用信息更合适
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.
這些中文問題你直接改吧
| // 避免使用版本号控制导致代码理解混乱 | ||
| // 用来清除 UserScript API 里的旧缓存 | ||
| const USERSCRIPTS_REGISTER_CONTROL = "0f5b5b01-eef8-4505-9a8e-b2fc416b2f63"; |
Copilot
AI
Nov 16, 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.
在注释"用来清除 UserScript 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.
copilot幻觉了
src/app/service/content/content.ts
Outdated
| // 向service_worker请求脚本列表及環境資訊 | ||
| client.pageLoad().then((o) => { | ||
| if (!o.ok) return; | ||
| const { injectScriptList, contentScriptList, envInfo } = o; | ||
| // 启动脚本:向 inject頁面 傳送脚本列表及環境資訊 |
Copilot
AI
Nov 16, 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.
注释中的"資訊"和"環境"使用了繁体中文字符,而项目的其他注释主要使用简体中文。为了保持一致性,建议将这些注释改为简体中文:"环境资讯"和"环境信息"。
| // 向service_worker请求脚本列表及環境資訊 | |
| client.pageLoad().then((o) => { | |
| if (!o.ok) return; | |
| const { injectScriptList, contentScriptList, envInfo } = o; | |
| // 启动脚本:向 inject頁面 傳送脚本列表及環境資訊 | |
| // 向service_worker请求脚本列表及环境信息 | |
| client.pageLoad().then((o) => { | |
| if (!o.ok) return; | |
| const { injectScriptList, contentScriptList, envInfo } = o; | |
| // 启动脚本:向 inject页面 传送脚本列表及环境信息 |
src/app/service/content/utils.ts
Outdated
| // --- 处理 resource --- | ||
| // --- 处理 scriptInfo --- | ||
| const scriptInfo = { ...script, resource, code: "" } as TScriptInfo; | ||
| // 删除其他不需要注入的 script 资讯 |
Copilot
AI
Nov 16, 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.
注释中的"資訊"使用了繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为简体中文:"脚本资讯"。
| // 删除其他不需要注入的 script 资讯 | |
| // 删除其他不需要注入的 script 信息 |
src/app/service/content/utils.ts
Outdated
| delete scriptInfo.ignoreVersion; // UserScript 裡面不需要知道用戶有沒有在更新時忽略 | ||
| delete scriptInfo.sort; // UserScript 裡面不需要知道用戶如何 sort | ||
| delete scriptInfo.error; | ||
| delete scriptInfo.subscribeUrl; // UserScript 裡面不需要知道用戶從何處訂閱 |
Copilot
AI
Nov 16, 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.
注释中多处使用了繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议进行以下修改:
- "裡面" → "里面"
- "用戶" → "用户"
- "訂閱" → "订阅"
- "從何處" → "从何处"
| delete scriptInfo.ignoreVersion; // UserScript 裡面不需要知道用戶有沒有在更新時忽略 | |
| delete scriptInfo.sort; // UserScript 裡面不需要知道用戶如何 sort | |
| delete scriptInfo.error; | |
| delete scriptInfo.subscribeUrl; // UserScript 裡面不需要知道用戶從何處訂閱 | |
| delete scriptInfo.ignoreVersion; // UserScript 里面不需要知道用户有没有在更新时忽略 | |
| delete scriptInfo.sort; // UserScript 里面不需要知道用户如何 sort | |
| delete scriptInfo.error; | |
| delete scriptInfo.subscribeUrl; // UserScript 里面不需要知道用户从何处订阅 |
src/app/service/content/utils.ts
Outdated
| delete scriptInfo.origin; // 脚本来源 | ||
| delete scriptInfo.runStatus; // 前台脚本不用 | ||
| delete scriptInfo.type; // 脚本类型總是普通脚本 | ||
| delete scriptInfo.status; // 脚本状态總是启用 |
Copilot
AI
Nov 16, 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.
注释中的"脚本状态總是启用"中,"總"是繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为"总是"。
| delete scriptInfo.status; // 脚本状态總是启用 | |
| delete scriptInfo.status; // 脚本状态总是启用 |
| /** | ||
| * 脚本加载信息。( Inject / Content 环境用,避免过多不必要资讯公开,减少页面加载资讯储存量 ) | ||
| * 包含脚本元数据与用户配置。 | ||
| */ |
Copilot
AI
Nov 16, 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.
注释中的"環境"使用了繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为简体中文:"脚本加载信息。( Inject / Content 环境用,避免过多不必要资讯公开,减少页面加载资讯存储量 )"。
注意:这个注释也包含了"資訊"和"儲存"等繁体字,建议一并修改为简体中文。
src/app/service/content/utils.ts
Outdated
| } | ||
|
|
||
| /** | ||
| * 脚本加载信息。(Inject/Content环境用,避免过多不必要资讯公开,减少页面加载资讯储存量) |
Copilot
AI
Nov 16, 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.
注释中的"資讯"、"儲存"和"環境"使用了繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为简体中文:"脚本加载信息。(Inject/Content环境用,避免过多不必要资讯公开,减少页面加载资讯存储量)"。
| * 脚本加载信息。(Inject/Content环境用,避免过多不必要资讯公开,减少页面加载资讯储存量) | |
| * 脚本加载信息。(Inject/Content环境用,避免过多不必要信息公开,减少页面加载信息存储量) |
概述 Descriptions
变更内容 Changes
截图 Screenshots