GM.registerMenuCommand

From GreaseSpot Wiki
Revision as of 14:45, 17 August 2022 by Arantius (talk | contribs) (underscore to dot, 4.x style API, in examples)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Description

This method allows user scripts to add an item to the User Script Commands menu.

Compatibility: Greasemonkey 4.11+

Syntax

function GM.registerMenuCommand( caption, commandFunc, accessKey )

Arguments

caption
String The caption to display on the menu item.
commandFunc
Function The function to call when this menu item is selected by the user.
accessKey
String A single character that can be used to select command when the menu is open. It should be a letter in the caption. [1]

History

This method existed in a similar but different form before Greasemonkey 4.0.

Returns

undefined

Examples

GM.registerMenuCommand("Hello, world (simple)", () => alert("Hello, world!"));
function hello() { ... }
GM.registerMenuCommand("Hello, world!", hello, "h");

See Also

The GM_config @require library is frequently used with GM.registerMenuCommand.