Difference between revisions of "GM.registerMenuCommand"

From GreaseSpot Wiki
Jump to navigationJump to search
m (→‎Examples: CSS change)
(Update for 4.0)
Line 1: Line 1:
{{DISPLAYTITLE:GM_registerMenuCommand}}
As of Greasemonkey 4.0, this method has been removed.


== Description ==
<!-- TODO: When it exists, link to the compatibility polyfill docs. -->
 
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+]]
 
== Syntax ==
 
{{Function|GM_registerMenuCommand|caption, commandFunc, accessKey}}
 
=== Arguments ===
 
; <code>caption</code>
: <code>String</code> The caption to display on the menu item.
; <code>commandFunc</code>
: <code>Function</code> The function to call when this menu item is selected by the user.
; <code>accessKey</code>
: <code>String</code> A single character that can be used to select command when the menu is open.  It should be a letter in the <code>caption</code>. [https://developer.mozilla.org/en/XUL/Attribute/accesskey]
 
==== History ====
 
In Greasemonkey [[Version history#0.9.2|0.9.2]], this API was changed.
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 ==
 
<code>undefined</code>
 
== Examples ==
 
<pre class='sample'>GM_registerMenuCommand("Hello, world (simple)", helloSimple);</pre>
 
<pre class='sample'>GM_registerMenuCommand("Hello, world!", hello, "h");</pre>
 
<pre class='sample-bad'>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]]
 
== 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.

Revision as of 10:06, 3 November 2017

As of Greasemonkey 4.0, this method has been removed.