GM.registerMenuCommand: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m Reverted edits by 202.177.245.247 (talk) to last revision by Arantius
Lil Devil (talk | contribs)
update for change in 0.9.2
Line 9: Line 9:
== Syntax ==
== Syntax ==


{{Function|GM_registerMenuCommand|caption, commandFunc, accelKey, accelModifiers, accessKey}}
{{Function|GM_registerMenuCommand|caption, commandFunc, accessKey}}


=== Arguments ===
=== Arguments ===
Line 35: Line 35:
<pre class='sample'>GM_registerMenuCommand("Hello, world (simple)", helloSimple);</pre>
<pre class='sample'>GM_registerMenuCommand("Hello, world (simple)", helloSimple);</pre>


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


<pre class='sample'>GM_registerMenuCommand("Hello, world! (again)", hello2, "e", "shift alt", "w");</pre>
<pre class='sample'>GM_registerMenuCommand("Hello, world! (again)", hello2, "e", "shift alt", "w");</pre>
The last example is in the pre-0.9.2 format. The 3rd and 4th arguments will be ignored in recent versions of Greasemonkey.


[[Category:API_Reference|R]]
[[Category:API_Reference|R]]

Revision as of 07:11, 28 May 2011


Description

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

Compatibility: Greasemonkey 0.2.5+

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

In Greasemonkey 0.9.2, this API was changed. Previously, it accepted five parameters including accelKey and accelModifiers which have been removed. See 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 accessKey.

Returns

undefined

Examples

GM_registerMenuCommand("Hello, world (simple)", helloSimple);
GM_registerMenuCommand("Hello, world!", hello, "h");
GM_registerMenuCommand("Hello, world! (again)", hello2, "e", "shift alt", "w");

The last example is in the pre-0.9.2 format. The 3rd and 4th arguments will be ignored in recent versions of Greasemonkey.

See Also

The GM_config @require library can handle many of the tasks that GM_registerMenuCommand is otherwise used for, in a more user-friendly manner.