GM.registerMenuCommand: Difference between revisions
From GreaseSpot Wiki
Jump to navigationJump to search
→See Also: Rephrase GM_config reference to make it even clearer that this is a 3rd party tool, not a native feature/function. |
|||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
== Description == | == Description == | ||
This method allows user scripts to add an item to the [[Greasemonkey_Manual:Monkey_Menu#The_Menu|User Script Commands]] menu. | This method allows user scripts to add an item to the [[Greasemonkey_Manual:Monkey_Menu#The_Menu|User Script Commands]] menu. | ||
Compatibility: [[Version_history# | Compatibility: [[Version_history#4.11|Greasemonkey 4.11+]] | ||
== Syntax == | == Syntax == | ||
{{Function| | {{Function|GM.registerMenuCommand|caption, commandFunc, accessKey}} | ||
=== Arguments === | === Arguments === | ||
Line 22: | Line 20: | ||
==== History ==== | ==== History ==== | ||
This method existed in a similar but different form before Greasemonkey 4.0. | |||
== Returns == | == Returns == | ||
Line 33: | Line 28: | ||
== Examples == | == Examples == | ||
<pre class='sample'> | <pre class='sample'>GM.registerMenuCommand("Hello, world (simple)", () => alert("Hello, world!"));</pre> | ||
<pre class='sample'> | <pre class='sample'>function hello() { ... } | ||
GM.registerMenuCommand("Hello, world!", hello, "h");</pre> | |||
[[Category:API_Reference|R]] | [[Category:API_Reference|R]] | ||
Line 44: | Line 37: | ||
== See Also == | == See Also == | ||
The | The third-party <code>@require</code> library "[[GM_config]]" by ''sizzlemctwizzle'' is frequently used with <code>GM.registerMenuCommand</code>. |
Latest revision as of 02:11, 13 December 2023
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 thecaption
. [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 third-party @require
library "GM_config" by sizzlemctwizzle is frequently used with GM.registerMenuCommand
.