二级菜单&分隔线#785
Conversation
|
§ 太抽象了吧,我觉得不如增加一个参数 |
There was a problem hiding this comment.
Pull Request Overview
This PR implements submenu and separator functionality for the GM_registerMenuCommand API using section sign (§) notation and empty names. It maintains compatibility with existing scripts while adding new hierarchical menu structure capabilities.
- 新增了使用 § 符号创建二级菜单的功能
- 增加了使用空名称创建分隔线的功能
- 重构了菜单生成逻辑以支持层级结构
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/pages/components/ScriptMenuList/index.tsx | 更新菜单项组件以处理§前缀并隐藏空名称的分隔线菜单 |
| src/app/service/service_worker/popup.ts | 重构菜单生成逻辑以支持二级菜单和分隔线功能 |
| title: menu.name, | ||
| const subMenuEntries = [] as chrome.contextMenus.CreateProperties[]; | ||
| let withMenuItem = false; | ||
| // eslint-disable-next-line prefer-const |
There was a problem hiding this comment.
使用 eslint-disable 注释来绕过 prefer-const 规则不是最佳实践。既然需要修改 name 变量,应该使用 let 声明并移除这个 eslint-disable 注释。
| // eslint-disable-next-line prefer-const | |
| // 如果是带输入框的菜单则不在页面内注册 | ||
| if (options?.inputType) return; | ||
| let level = 3; | ||
| if (name[0] === "\xA7") { |
There was a problem hiding this comment.
使用十六进制转义序列 \xA7 不如直接使用字符 § 清晰易读。建议改为 if (name[0] === '§') { 以提高代码可读性。
| if (name[0] === "\xA7") { | |
| if (name[0] === "§") { |
There was a problem hiding this comment.
避免build后脚本代码包括非通用ASCII字符
| } | ||
| })(); | ||
|
|
||
| const menuName = menu.name.replace(/^\xA7+/, "").trim(); |
There was a problem hiding this comment.
与上面相同,这里的正则表达式使用 \xA7 不如使用 § 字符清晰。建议改为 /^§+/ 以提高代码可读性。
| const menuName = menu.name.replace(/^\xA7+/, "").trim(); | |
| const menuName = menu.name.replace(/^§+/, "").trim(); |
There was a problem hiding this comment.
避免build后脚本代码包括非通用ASCII字符
不会吧 原来 加了 options.nested 3abd3f9 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
这个PR还在草稿中,是等 #790 吗? |
是。 |
|
見 PR #831 |
概述
#781
例子
变更内容
调整 src/pages/components/ScriptMenuList/index.tsx
对 src/app/service/service_worker/popup.ts 修改增加功能
截图