Skip to content

✨ GM_info 应暴露当前脚本 UUID (GM_info.uuid),让脚本猫与 Violentmonkey 的实现一致 (#1784) - #1787

Draft
CodFrm wants to merge 1 commit into
mainfrom
feat/1784-gm-info-uuid
Draft

CodFrm wants to merge 1 commit into
mainfrom
feat/1784-gm-info-uuid

Conversation

@CodFrm

@CodFrm CodFrm commented Oct 8, 2026

Copy link
Copy Markdown
Member

Checklist / 检查清单

  • Fixes mentioned issues / 修复已提及的问题
  • Code reviewed by human / 代码通过人工检查
  • Changes tested / 已完成测试

Description / 描述

Close #1784

背景

#1784 请求通过 GM_info.uuid / GM.info.uuid 获取当前脚本的 UUID,维护者在 issue 中确认与 Violentmonkey 保持一致(VM 在 GM_info 顶层暴露 uuid: string)。

本次改动

  • evaluateGMInfo(src/app/service/content/gm_api/gm_info.ts)在顶层返回 uuid: script.uuid。@grant none 与沙箱两条路径都由这个函数生成 GM_info,且 GM.info 与 GM_info 是同一对象,因此两个入口同时生效;后台/定时脚本复用同一 ExecScript 构建逻辑。
  • src/types/scriptcat.d.ts、src/types/scriptcat.zh-CN.d.ts、src/template/scriptcat.d.tpl(编辑器内置类型提示)补充 uuid: string。

暴露的是 ScriptCat 已有的脚本 UUID,不新增权限,也不是浏览器/设备级标识。脚本更新时复用原 UUID(src/pkg/utils/script.ts 中 prepareScriptByCode 沿用 old.uuid),所以注释写明"更新后保持不变"。

已知限制

issue 中希望说明复制、重装、导入、恢复、同步等场景下 UUID 的行为,这部分属于 scriptcat.org 文档站,未在本 PR 中处理。

验证

基于 base 54999260 / head 033042f7:

  • 先写测试 GM_info.uuid 与 GM.info.uuid 返回当前脚本 UUID(none / sandbox),改动前两种模式均失败(收到 undefined),改动后通过。
  • pnpm vitest run src/app/service/content/:12 个文件、240 个用例全部通过。
  • tsc --noEmit、eslint(改动文件)、prettier 检查通过;push 钩子的 typecheck / prettier / issue 模板检查通过。
  • 未在构建后的扩展中手动验证。

@cyfung1031 cyfung1031 changed the title ✨ GM_info 暴露当前脚本 UUID (GM_info.uuid),与 Violentmonkey 一致 (#1784) ✨ GM_info 应暴露当前脚本 UUID (GM_info.uuid),让脚本猫与 Violentmonkey 的实现一致 (#1784) Oct 8, 2026
@cyfung1031
cyfung1031 marked this pull request as draft October 8, 2026 12:09
@cyfung1031

cyfung1031 commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator

1784 的观点站不住脚
ScriptCat uuid 不是固定(相对于安装新脚本情景),userscript author 拿到了也没用
又不是能跨脚本通讯什么的,拿到的uuid永远就是自己脚本那个固定(相对于已安装的「自己」)随机生成 id
不会因为脚本更新而改。跟安装url又没关系

暴露前应先搞清楚用途
否则跟VM只是看起来一样但实际性质不同又是一种不相容

@CodFrm

CodFrm commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

1784 的观点站不住脚

ScriptCat uuid 不是固定(相对于安装新脚本情景),userscript author 拿到了也没用

又不是能跨脚本通讯什么的,拿到的uuid永远就是自己脚本那个固定(相对于已安装的「自己」)随机生成 id

不会因为脚本更新而改。跟安装url又没关系

暴露前应先搞清楚用途

否则跟VM只是看起来一样但实际性质不同又是一种不相容

我想错了,确实场景有限

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.

[Feature] Expose the current userscript UUID through GM_info.uuid

2 participants