Merged
Conversation
Contributor
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
在 onChange 回调中使用了非空断言 script!,但 script 可能为 undefined。虽然外层 Descriptions 组件总是渲染,但当 script 为 undefined 时,这个 InputTag 组件依然可以被用户交互,会导致运行时错误。应该添加 if (!script) return; 检查或者禁用输入框。
Suggested change
| scriptClient.updateMetadata(script!.uuid, "tag", tags).then(() => { | |
| if (!script) return; | |
| scriptClient.updateMetadata(script.uuid, "tag", tags).then(() => { |
Comment on lines
215
to
217
| scriptClient.setCheckUpdateUrl(script!.uuid, checkUpdate, checkUpdateUrl).then(() => { | ||
| Message.success(t("update_success")!); | ||
| }); |
There was a problem hiding this comment.
在 Input 的 onBlur 回调中使用了非空断言 script!,但 script 可能为 undefined。当 script 为空时,用户仍可以与输入框交互并触发 onBlur 事件,会导致运行时错误。建议添加空值检查。
Suggested change
| 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")!); | |
| }); | |
| } |
cyfung1031
pushed a commit
to cyfung1031/scriptcat
that referenced
this pull request
Nov 6, 2025
* wip: 设置 * 运行时机 * 根据copilot意见修改 * 处理翻译
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 #888
变更内容 Changes
增加脚本运行时期选项
截图 Screenshots