javascript - GM_registerMenuCommand()的 `accessKey`参数是什么,如何使用?

标签 javascript greasemonkey tampermonkey userscripts

我在看 GM_registerMenuCommand Tampermonkey 中的函数,我注意到第三个参数称为 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    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 安装并运行它,你会看到(点击查看大图):

Tampermonkey screenshot


注意事项:

  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 .

关于javascript - GM_registerMenuCommand()的 `accessKey`参数是什么,如何使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56024629/

相关文章:

javascript - 如何隐藏表格中的每隔一行?

javascript - 如何使用tampermonkey脚本附加大量数据?

javascript - 使用 JQuery 缓动

javascript - Sails.js Hook 路由如何连接到策略?

javascript - 删除div节点的子节点

javascript - Greasemonkey提交登录表单但用户名和密码未填写?

javascript - 无法通过 Firefox 中的键获取存储的对象值

javascript - 如何访问选项标签

javascript - 在 HTML 中输出 Ruby 数组

javascript - 使用javascript在网页中查找和替换