GM_registerMenuCommand() 的 `accessKey` 参数是什么以及如何使用它?

What is the `accessKey` parameter of GM_registerMenuCommand() and how to use it?

我在查看 Tampermonkey 中的 GM_registerMenuCommand 函数时注意到第三个参数 accessKey 并认为它是传递一个热键来触发此命令。

传递的参数的格式是什么?我假设这是它的作用是不是错了?

我在任何地方都找不到关于该参数的文档。 这里有人用过吗?

syntax for that function is:

GM_registerMenuCommand (menuName, callbackFunction, accessKey)

来自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 安装并 运行 您将看到(点击查看大图):


备注:

  1. Violentmonkey ignores the accessKey parameter, for now.
  2. Greasemonkey 4+ has borked this feature.  Per usual.
  3. 你可以set a keyboard command to activate the Tampermonkey icon/menu in Chrome.
  4. 键盘图标激活目前似乎在 Firefox 中不起作用,但 a workaround is scheduled for Firefox version 67