Difference between revisions of "GM.registerMenuCommand"

From GreaseSpot Wiki
Jump to navigationJump to search
m (Reverted edits by 202.177.245.247 (talk) to last revision by Arantius)
m (Arantius moved page GM registerMenuCommand to GM.registerMenuCommand: New GM-4 name with dot, not underscore.)
 
(10 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:GM_registerMenuCommand}}
== 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#0.2.5|Greasemonkey 0.2.5+]]
Compatibility: [[Version_history#4.11|Greasemonkey 4.11+]]


== Syntax ==
== Syntax ==


{{Function|GM_registerMenuCommand|caption, commandFunc, accelKey, accelModifiers, accessKey}}
{{Function|GM.registerMenuCommand|caption, commandFunc, accessKey}}


=== Arguments ===
=== Arguments ===
Line 22: Line 20:
==== History ====
==== History ====


In Greasemonkey [[Version history#0.9.2|0.9.2]], this API was changed.
This method existed in a similar but different form before Greasemonkey 4.0.
Previously, it accepted five parameters including <code>accelKey</code> and <code>accelModifiers</code> which have been removed.
See [http://wiki.greasespot.net/index.php?title=GM_registerMenuCommand&oldid=6238 this page's history] for a description of them.
If a script passes all five parameters, in the old style, then the fifth argument is used for <code>accessKey</code>.


== Returns ==
== Returns ==
Line 33: Line 28:
== Examples ==
== Examples ==


<pre class='sample'>GM_registerMenuCommand("Hello, world (simple)", helloSimple);</pre>
<pre class='sample'>GM_registerMenuCommand("Hello, world (simple)", () => alert("Hello, world!"));</pre>
 
<pre class='sample'>GM_registerMenuCommand("Hello, world!", hello, "e", "control", "h");</pre>


<pre class='sample'>GM_registerMenuCommand("Hello, world! (again)", hello2, "e", "shift alt", "w");</pre>
<pre class='sample'>function hello() { ... }
GM_registerMenuCommand("Hello, world!", hello, "h");</pre>


[[Category:API_Reference|R]]
[[Category:API_Reference|R]]
Line 43: Line 37:
== See Also ==
== See Also ==


The [[GM_config]] <code>@require</code> library can handle many of the tasks that <code>GM_registerMenuCommand</code> is otherwise used for, in a more user-friendly manner.
The [[GM_config]] <code>@require</code> library is frequently used with <code>GM.registerMenuCommand</code>.

Latest revision as of 21:10, 27 January 2021

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.