Skip to content

Conversation

@cyfung1031
Copy link
Collaborator

跟 TM 一样。会显示 "0.0",但内部处理不设为 "0.0"
只在显示改变
(部份情况会显示 "N/A" )

安装或更新时可接受不输入 "0.0"

这样 VM的导出 和 其他TM脚本 都能正常安装了

@cyfung1031 cyfung1031 linked an issue Feb 7, 2026 that may be closed by this pull request
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 让脚本元数据中的 @version 字段在缺失或为空时也能被接受,从而提升对 Tampermonkey/Violentmonkey 导出脚本的兼容性;同时在多个页面/服务逻辑中对版本展示与比较增加了默认回退值。

Changes:

  • 安装/解析流程不再强制要求 @version 非空(允许缺失/空值)。
  • UI 中多个列表视图对缺失版本统一回退显示为 "0.0",安装页部分场景显示 "N/A"
  • 更新检查、忽略版本逻辑与 GM_info 输出对缺失版本做了默认值处理,避免因版本缺失导致流程中断。

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/pkg/utils/script.ts 放开 @version 非空校验,允许缺失/空值版本进入安装/更新流程
src/pages/options/routes/SubscribeList.tsx 订阅列表版本列缺失时回退显示 "0.0"
src/pages/options/routes/ScriptList/ScriptTable.tsx 脚本表格视图版本列缺失时回退显示 "0.0"
src/pages/options/routes/ScriptList/ScriptCard.tsx 卡片视图版本渲染条件调整(当前会在缺失/空版本时不显示)
src/pages/install/App.tsx 安装页旧版本/当前版本展示逻辑调整,对缺失版本回退 "N/A" 并增强类型判断
src/pages/batchupdate/App.tsx 批量更新页忽略版本判断增加类型保护,避免非字符串参与比较/传参
src/app/types.d.ts IsInstalledResponse 中 installed=true 时的 version 改为必填 string
src/app/service/service_worker/subscribe.ts 订阅更新检查对缺失版本回退 "0.0" 并继续比较
src/app/service/service_worker/script_update_check.ts 更新检查目标站点过滤逻辑对版本取值增加类型保护
src/app/service/service_worker/script.ts 脚本更新检查/日志版本字段回退 "0.0";isInstalled 返回缺失版本回退;新增了调试 console 输出
src/app/service/content/gm_api/gm_info.ts GM_info 的 script.version 在缺失时回退 "0.0"
Comments suppressed due to low confidence (2)

src/app/service/service_worker/script.ts:1194

  • isInstalled 里新增的 console.log/console.error(还包含 script 对象)会把用户脚本信息输出到控制台,容易造成噪音与潜在信息泄露,也不适合发布版本。建议移除这些调试输出,若需要诊断请改用现有 logger 并加可控的 debug 开关。
          return script;
        })
      )
    ).sort((a, b) => a.sort - b.sort);

    await this.scriptDAO.updates(batchUpdate);

src/pages/options/routes/ScriptList/ScriptCard.tsx:241

  • 当前卡片视图里版本展示条件改成了 item.metadata.version?.[0] 为真才渲染;当脚本没有 @Version@Version 为空字符串时,这里会直接不显示版本,与表格视图/订阅列表里统一回退显示 "0.0" 的行为不一致,也与 PR 描述“显示 0.0”不完全匹配。建议这里也做同样的回退展示,或至少保持各视图一致。
                <div className="tw-flex tw-flex-row tw-gap-4 tw-text-sm tw-text-gray-500">
                  {item.metadata.version?.[0] && (
                    <div>
                      <span className="tw-font-medium">
                        {t("version")}
                        {": "}
                      </span>
                      <span>{item.metadata.version[0]}</span>
                    </div>

Comment on lines +203 to +205
const scriptVersion = metadata.version?.[0];
const oldScriptVersion = typeof scriptVersion === "string" ? scriptVersion : "N/A";
setOldScriptVersion(oldScriptVersion);
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

安装页这里把缺失/空的版本显示为 "N/A",而其它列表页回退显示为 "0.0"。如果目标是“跟 TM 一样显示 0.0”,建议这里也统一回退为 "0.0";如果确实需要区分未知(N/A)与空值,请在 UI/文案上明确规则并保持各页面一致。

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

這裡寫 N/A 會比較好

Comment on lines 82 to 91
// 不接受空白name
if (!metadata.name?.[0]) {
throw new Error(i18n_t("error_script_name_required"));
}
// 不接受空白version
if (!metadata.version?.[0]) {
throw new Error(i18n_t("error_script_version_required"));
}
// 可接受空白namespace
if (metadata.namespace === undefined) {
throw new Error(i18n_t("error_script_namespace_required"));
}
// 可接受空白version
let type = SCRIPT_TYPE_NORMAL;
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

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

prepareScriptByCode 现在放开了 @Version 缺失/空值的校验,这是行为变更。仓库里已有 src/pkg/utils/script.test.ts 覆盖 parseMetadata 的多种情况,建议补充用例:1) 无 @Version;2) @version 但值为空白,确保 prepareScriptByCode 不再抛 error_script_version_required,并且后续 metadata/version 的表现符合预期。

Copilot generated this review using guidance from repository custom instructions.
Copy link
Member

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

cyfung1031 and others added 2 commits February 12, 2026 20:04
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@CodFrm CodFrm Feb 12, 2026

Choose a reason for hiding this comment

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

应该为 prepareScriptByCode 添加单元测试才对,parseMetadata有覆盖过了,这添加的这几个没什么用,我处理一下

@CodFrm CodFrm merged commit 3645f64 into scriptscat:release/v1.3 Feb 12, 2026
3 checks passed
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.

[BUG] Import Script Failed - @version shall be optional

2 participants