Skip to content

Conversation

@CodFrm
Copy link
Member

@CodFrm CodFrm commented Nov 1, 2025

概述 Descriptions

close #888

变更内容 Changes

增加脚本运行时期选项

截图 Screenshots

@CodFrm CodFrm requested a review from Copilot November 1, 2025 05:19
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为脚本设置界面添加了"运行时机"(Run Timing)配置选项,并修复了类型安全性问题。

  • 添加了 script_run_at 配置选项,支持 document-start/body/end/idle 和 early-start 等执行时机
  • ScriptSetting 组件的 script prop 类型从 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(() => {
Copy link

Copilot AI Nov 1, 2025

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; 检查或者禁用输入框。

Suggested change
scriptClient.updateMetadata(script!.uuid, "tag", tags).then(() => {
if (!script) return;
scriptClient.updateMetadata(script.uuid, "tag", tags).then(() => {

Copilot uses AI. Check for mistakes.
Comment on lines 215 to 217
scriptClient.setCheckUpdateUrl(script!.uuid, checkUpdate, checkUpdateUrl).then(() => {
Message.success(t("update_success")!);
});
Copy link

Copilot AI Nov 1, 2025

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 事件,会导致运行时错误。建议添加空值检查。

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")!);
});
}

Copilot uses AI. Check for mistakes.
@CodFrm CodFrm merged commit b0ea187 into release/v1.3 Nov 3, 2025
3 of 4 checks passed
cyfung1031 pushed a commit to cyfung1031/scriptcat that referenced this pull request Nov 6, 2025
* wip: 设置

* 运行时机

* 根据copilot意见修改

* 处理翻译
@CodFrm CodFrm deleted the develop/setting branch December 6, 2025 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants