Skip to content

Conversation

@cyfung1031
Copy link
Collaborator

概述 Descriptions

变更内容 Changes

截图 Screenshots

@cyfung1031 cyfung1031 marked this pull request as draft November 15, 2025 02:29
@cyfung1031 cyfung1031 force-pushed the pr-pageLoad-optimize-003 branch from ef9f0f2 to 0866918 Compare November 15, 2025 03:36
@cyfung1031 cyfung1031 force-pushed the pr-pageLoad-optimize-003 branch from 0866918 to cf0d22c Compare November 15, 2025 03:39
@CodFrm
Copy link
Member

CodFrm commented Nov 15, 2025

看起来修了这个就可以发下一个beta版本了,怎么变draft了

@cyfung1031
Copy link
Collaborator Author

cyfung1031 commented Nov 15, 2025

看起来修了这个就可以发下一个beta版本了,怎么变draft了

可以的话 #906 #926 先合一下吧。PR内容很少。
看你打算合并 #951 但不 #950 ?
#950 包含了 deleteValue 的 bug fix. 如果先处理 bug fix 的部份,就 #943. 修改内容真的5句左右。
其他的UI什么就看你的吧。没所谓。

#952 这个
我看到有一些还有改善的部份,一并处理一下

@cyfung1031 cyfung1031 marked this pull request as ready for review November 15, 2025 08:05
@cyfung1031
Copy link
Collaborator Author

@CodFrm 改好了。

之前的 @early-start 里面的scriptInfo 连 code 都包含了
现在删了。见 trimScriptInfo

一些写法也改了一下
代码修改不影响功能

@cyfung1031 cyfung1031 changed the title 整理 inject & content 整理 inject & content,修改 pageLoad 资讯量传递 Nov 15, 2025
@CodFrm CodFrm added P0 🚑 需要紧急处理的内容 hotfix 需要尽快更新到扩展商店 labels Nov 15, 2025
@CodFrm
Copy link
Member

CodFrm commented Nov 15, 2025

看起来修了这个就可以发下一个beta版本了,怎么变draft了

可以的话 #906 #926 先合一下吧。PR内容很少。 看你打算合并 #951 但不 #950 ? #950 包含了 deleteValue 的 bug fix. 如果先处理 bug fix 的部份,就 #943. 修改内容真的5句左右。 其他的UI什么就看你的吧。没所谓。

#952 这个 我看到有一些还有改善的部份,一并处理一下

好我处理一下 #906#926

没打算合并 #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的内容

@cyfung1031
Copy link
Collaborator Author

cyfung1031 commented Nov 15, 2025

没打算合并 #951#950 到v1.2,

@CodFrm 那我重新打開 #943

@cyfung1031
Copy link
Collaborator Author

@CodFrm 这个会合并到 1.2 吗? 还是要先折开?

@CodFrm
Copy link
Member

CodFrm commented Nov 15, 2025

@CodFrm 这个会合并到 1.2 吗? 还是要先折开?

合吧,要合的我都标记hotfix

@CodFrm CodFrm requested a review from Copilot November 16, 2025 04:38
Copilot finished reviewing on behalf of CodFrm November 16, 2025 04:41
Copy link
Contributor

Copilot AI left a 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 方法,将脚本列表分为 injectScriptListcontentScriptList,并优化返回结构

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 重命名 initsetEnvInfostartstartScripts,更新 execEarlyScript 以接收 scriptInfo 参数
src/app/service/content/inject.ts 拆分 init 方法,添加 setEnvInfostartScriptsonInjectPageLoaded 方法
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 重构 pageLoadstart 方法,使用 Set 替代 Map 存储 content 脚本
src/app/repo/scripts.ts 添加 ScriptLoadInfoTScriptInfoTClientPageLoadInfo 类型定义
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

Comment on lines 1211 to 1237
// 发布给 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 的资讯
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释中的"資讯"和"資料"使用了繁体中文字符,而项目的其他注释主要使用简体中文。为了保持一致性,建议将这些注释改为简体中文:"发布给 Popup 的资讯"和"发布给 inject 和 content 的资讯"。

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

简体中文用信息更合适

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這些中文問題你直接改吧

Comment on lines +54 to +56
// 避免使用版本号控制导致代码理解混乱
// 用来清除 UserScript API 里的旧缓存
const USERSCRIPTS_REGISTER_CONTROL = "0f5b5b01-eef8-4505-9a8e-b2fc416b2f63";
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在注释"用来清除 UserScript API 里的旧缓存"中,"裡"是繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为"里"。

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copilot幻觉了

Comment on lines 129 to 133
// 向service_worker请求脚本列表及環境資訊
client.pageLoad().then((o) => {
if (!o.ok) return;
const { injectScriptList, contentScriptList, envInfo } = o;
// 启动脚本:向 inject頁面 傳送脚本列表及環境資訊
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释中的"資訊"和"環境"使用了繁体中文字符,而项目的其他注释主要使用简体中文。为了保持一致性,建议将这些注释改为简体中文:"环境资讯"和"环境信息"。

Suggested change
// 向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页面 传送脚本列表及环境信息

Copilot uses AI. Check for mistakes.
// --- 处理 resource ---
// --- 处理 scriptInfo ---
const scriptInfo = { ...script, resource, code: "" } as TScriptInfo;
// 删除其他不需要注入的 script 资讯
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释中的"資訊"使用了繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为简体中文:"脚本资讯"。

Suggested change
// 删除其他不需要注入的 script 资讯
// 删除其他不需要注入的 script 信息

Copilot uses AI. Check for mistakes.
Comment on lines 119 to 122
delete scriptInfo.ignoreVersion; // UserScript 裡面不需要知道用戶有沒有在更新時忽略
delete scriptInfo.sort; // UserScript 裡面不需要知道用戶如何 sort
delete scriptInfo.error;
delete scriptInfo.subscribeUrl; // UserScript 裡面不需要知道用戶從何處訂閱
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释中多处使用了繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议进行以下修改:

  • "裡面" → "里面"
  • "用戶" → "用户"
  • "訂閱" → "订阅"
  • "從何處" → "从何处"
Suggested change
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 里面不需要知道用户从何处订阅

Copilot uses AI. Check for mistakes.
delete scriptInfo.origin; // 脚本来源
delete scriptInfo.runStatus; // 前台脚本不用
delete scriptInfo.type; // 脚本类型總是普通脚本
delete scriptInfo.status; // 脚本状态總是启用
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释中的"脚本状态總是启用"中,"總"是繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为"总是"。

Suggested change
delete scriptInfo.status; // 脚本状态總是启用
delete scriptInfo.status; // 脚本状态总是启用

Copilot uses AI. Check for mistakes.
Comment on lines +118 to +121
/**
* 脚本加载信息。( Inject / Content 环境用,避免过多不必要资讯公开,减少页面加载资讯储存量 )
* 包含脚本元数据与用户配置。
*/
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释中的"環境"使用了繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为简体中文:"脚本加载信息。( Inject / Content 环境用,避免过多不必要资讯公开,减少页面加载资讯存储量 )"。

注意:这个注释也包含了"資訊"和"儲存"等繁体字,建议一并修改为简体中文。

Copilot uses AI. Check for mistakes.
}

/**
* 脚本加载信息。(Inject/Content环境用,避免过多不必要资讯公开,减少页面加载资讯储存量)
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

注释中的"資讯"、"儲存"和"環境"使用了繁体中文字符。为了与项目中的其他简体中文注释保持一致,建议改为简体中文:"脚本加载信息。(Inject/Content环境用,避免过多不必要资讯公开,减少页面加载资讯存储量)"。

Suggested change
* 脚本加载信息。(Inject/Content环境用,避免过多不必要资讯公开,减少页面加载资讯储存量
* 脚本加载信息。(Inject/Content环境用,避免过多不必要信息公开,减少页面加载信息存储量

Copilot uses AI. Check for mistakes.
@CodFrm CodFrm merged commit 0554159 into scriptscat:main Nov 16, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotfix 需要尽快更新到扩展商店 P0 🚑 需要紧急处理的内容

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants