GM_registerMenuCommand() 的 `accessKey` 参数是什么以及如何使用它?
What is the `accessKey` parameter of GM_registerMenuCommand() and how to use it?
我在查看 Tampermonkey 中的 GM_registerMenuCommand 函数时注意到第三个参数 accessKey
并认为它是传递一个热键来触发此命令。
传递的参数的格式是什么?我假设这是它的作用是不是错了?
我在任何地方都找不到关于该参数的文档。
这里有人用过吗?
GM_registerMenuCommand (menuName, callbackFunction, accessKey)
- 其中
accessKey
,如果提供,必须是字符串 passed-in 的单个字母,如 menuName
。
它是用于 facilitate Good UI by adding keyboard-only support. 的菜单“访问键”
来自Menu Design Guidelines(8号):
Dropdowns (both menus and boxes) should support not only mouse input, but keys as well. In dropdown menus, access keys should enable users to quickly select a visible option without using the mouse. In a dropdown box, users should be able to type a letter and quickly navigate to options starting with that letter.
(已强调。)
重要:Access keys are different from, and in addition to, any command shortcuts ("hotkeys").
这里有一个示例 Tampermonkey 脚本示例,说明了用法:
// ==UserScript==
// @name _GM_registerMenuCommand demo
// @match
// @match *://YOUR_SERVER.COM/YOUR_PATH/*
// @grant GM_registerMenuCommand
// ==/UserScript==
/*-- GM_registerMenuCommand (menuName, callbackFunction, accessKey)
*/
GM_registerMenuCommand ("Say Hello", helloFunc, "H");
function helloFunc () {
console.log ("Say hello to my little script.");
}
如果您通过 Tampermonkey 安装并 运行 您将看到(点击查看大图):
备注:
我在查看 Tampermonkey 中的 GM_registerMenuCommand 函数时注意到第三个参数 accessKey
并认为它是传递一个热键来触发此命令。
传递的参数的格式是什么?我假设这是它的作用是不是错了?
我在任何地方都找不到关于该参数的文档。 这里有人用过吗?
GM_registerMenuCommand (menuName, callbackFunction, accessKey)
- 其中
accessKey
,如果提供,必须是字符串 passed-in 的单个字母,如menuName
。
它是用于 facilitate Good UI by adding keyboard-only support. 的菜单“访问键”
来自Menu Design Guidelines(8号):
Dropdowns (both menus and boxes) should support not only mouse input, but keys as well. In dropdown menus, access keys should enable users to quickly select a visible option without using the mouse. In a dropdown box, users should be able to type a letter and quickly navigate to options starting with that letter.
(已强调。)
重要:Access keys are different from, and in addition to, any command shortcuts ("hotkeys").
这里有一个示例 Tampermonkey 脚本示例,说明了用法:
// ==UserScript==
// @name _GM_registerMenuCommand demo
// @match
// @match *://YOUR_SERVER.COM/YOUR_PATH/*
// @grant GM_registerMenuCommand
// ==/UserScript==
/*-- GM_registerMenuCommand (menuName, callbackFunction, accessKey)
*/
GM_registerMenuCommand ("Say Hello", helloFunc, "H");
function helloFunc () {
console.log ("Say hello to my little script.");
}
如果您通过 Tampermonkey 安装并 运行 您将看到(点击查看大图):