我在看 GM_registerMenuCommand Tampermonkey 中的函数,我注意到第三个参数称为 accessKey
并认为它是传递一个热键来触发这个命令。
传递的参数的格式是什么,我假设这是它的作用是不是错了?
我在任何地方都找不到有关该参数的文档。 这里有人用过吗?
最佳答案
GM_registerMenuCommand (menuName, callbackFunction, accessKey)
- 其中
accessKey
(如果提供)必须是作为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 https://stackoverflow.com/questions/56024629/*
// @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 安装并运行它,你会看到(点击查看大图):
注意事项:
关于javascript - GM_registerMenuCommand()的 `accessKey`参数是什么,如何使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56024629/