Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
本 PR 解决了 early 脚本(document-start 脚本)的 URL 匹配问题。主要将 URL 匹配逻辑重构为可复用的函数,并为包含正则表达式的 URL 模式添加了运行时匹配检查。
关键变更:
- 将
UrlMatch类中的 URL 匹配逻辑提取为独立的urlMatch和urlExclude函数 - 为 early 脚本添加
scriptUrlPatterns字段,在运行时进行 URL 匹配验证 - 更新了 USERSCRIPTS_REGISTER_CONTROL UUID 以触发脚本重新注册
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pkg/utils/match.ts | 提取 URL 匹配逻辑为 urlMatch 和 urlExclude 函数,提高代码复用性 |
| src/pkg/utils/match.test.ts | 为新增的 urlMatch 和 urlExclude 函数添加测试用例 |
| src/app/service/service_worker/utils.ts | 更新 parseScriptLoadInfo 以传递正则表达式 URL 模式给 early 脚本 |
| src/app/service/service_worker/runtime.ts | 更新脚本编译流程以包含 URL 模式参数,并更新缓存控制 UUID |
| src/app/service/content/script_executor.ts | 在 content 环境中添加 early 脚本的运行时 URL 匹配检查 |
| src/app/repo/scripts.ts | 定义 EarlyScriptLoadInfo 接口以支持带 URL 模式的 early 脚本 |
cyfung1031
reviewed
Dec 19, 2025
cyfung1031
reviewed
Dec 19, 2025
| } | ||
| let result: boolean; | ||
| if (isOnlyExclude) { | ||
| result = !urlExclude(window.location.href, detail.scriptInfo.scriptUrlPatterns); // 是否要排除 |
Collaborator
There was a problem hiding this comment.
想完的结果是 urlExclude = !urlInclude ...
见单元测试新加的例子
Collaborator
There was a problem hiding this comment.
這個也很正常吧。不是互斥的話就很奇怪了
當然 isUrlExcluded也是可以保留的
看你吧
Member
Author
There was a problem hiding this comment.
我的写法被你改动了,之前的逻辑是只校验这个url是不是被排除的,而不是现在的包含在include 或 排除,不过这样包含的情况更全面一些,那就不用检查表达式做判断了,直接判断 isUrlIncluded/isUrlExcluded 即可
cyfung1031
reviewed
Dec 19, 2025
| const scriptCodes = {} as Record<string, string>; | ||
| // 更新资源使用了file协议的脚本 | ||
| const scriptsWithUpdatedResources = new Map<string, ScriptLoadInfo>(); | ||
| const scriptsWithUpdatedResources = new Map<string, ScriptLoadInfo & { scriptUrlPatterns: URLRuleEntry[] }>(); |
Collaborator
There was a problem hiding this comment.
個人建議 ScriptLoadInfo直接加個
scriptUrlPatterns?: URLRuleEntry[]
就好
不然一大堆 extends extends看到就頭暈
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述 Descriptions
close #1075
变更内容 Changes
截图 Screenshots