-
Notifications
You must be signed in to change notification settings - Fork 310
脚本运行时期选项 #895
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
脚本运行时期选项 #895
Conversation
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为脚本设置界面添加了"运行时机"(Run Timing)配置选项,并修复了类型安全性问题。
- 添加了
script_run_at配置选项,支持 document-start/body/end/idle 和 early-start 等执行时机 - 将
ScriptSetting组件的scriptprop 类型从Script!改为可选的Script | undefined,提升类型安全性 - 更新了脚本运行环境的默认值,从 "all" 改为 "default"
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/options/routes/script/ScriptEditor.tsx | 移除了非空断言操作符,将 currentScript! 改为 currentScript |
| src/pages/components/ScriptSetting/index.tsx | 主要改动:支持 script prop 为 undefined,添加运行时机选择器,将 scriptDAO 移入 useEffect,添加多处非空断言 |
| src/locales/zh-TW/translation.json | 添加繁体中文 "运行时机" 翻译 |
| src/locales/zh-CN/translation.json | 添加简体中文 "运行时机" 翻译 |
| src/locales/vi-VN/translation.json | 添加越南语 "Thời điểm chạy" 翻译 |
| src/locales/ru-RU/translation.json | 添加俄语 "Время выполнения" 翻译 |
| src/locales/ja-JP/translation.json | 添加日语 "実行タイミング" 翻译 |
| src/locales/en-US/translation.json | 添加英语 "Run Timing" 翻译 |
| src/locales/de-DE/translation.json | 添加德语 "Ausführungszeitpunkt" 翻译 |
| src/locales/ach-UG/translation.json | 添加翻译占位符并更新了其他键的ID |
| onChange={(tags) => { | ||
| setScriptTags(tags); | ||
| scriptClient.updateMetadata(script.uuid, "tag", tags).then(() => { | ||
| scriptClient.updateMetadata(script!.uuid, "tag", tags).then(() => { |
Copilot
AI
Nov 1, 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.
在 onChange 回调中使用了非空断言 script!,但 script 可能为 undefined。虽然外层 Descriptions 组件总是渲染,但当 script 为 undefined 时,这个 InputTag 组件依然可以被用户交互,会导致运行时错误。应该添加 if (!script) return; 检查或者禁用输入框。
| scriptClient.updateMetadata(script!.uuid, "tag", tags).then(() => { | |
| if (!script) return; | |
| scriptClient.updateMetadata(script.uuid, "tag", tags).then(() => { |
| scriptClient.setCheckUpdateUrl(script!.uuid, checkUpdate, checkUpdateUrl).then(() => { | ||
| Message.success(t("update_success")!); | ||
| }); |
Copilot
AI
Nov 1, 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.
在 Input 的 onBlur 回调中使用了非空断言 script!,但 script 可能为 undefined。当 script 为空时,用户仍可以与输入框交互并触发 onBlur 事件,会导致运行时错误。建议添加空值检查。
| scriptClient.setCheckUpdateUrl(script!.uuid, checkUpdate, checkUpdateUrl).then(() => { | |
| Message.success(t("update_success")!); | |
| }); | |
| if (script) { | |
| scriptClient.setCheckUpdateUrl(script.uuid, checkUpdate, checkUpdateUrl).then(() => { | |
| Message.success(t("update_success")!); | |
| }); | |
| } |
* wip: 设置 * 运行时机 * 根据copilot意见修改 * 处理翻译
概述 Descriptions
close #888
变更内容 Changes
增加脚本运行时期选项
截图 Screenshots