GM.registerMenuCommand: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(→‎Arguments: documentation, mostly as links to the underlying Mozilla attributes)
(→‎Syntax: update for change in 0.9.2)
Line 17: Line 17:
; <code>commandFunc</code>
; <code>commandFunc</code>
: <code>Function</code> The function to call when this menu item is selected by the user.
: <code>Function</code> The function to call when this menu item is selected by the user.
; <code>accelKey</code>
: <code>String</code> or <codeNumber</code> A single character or keycode that can trigger the command.  (See accelerator notes section.)
; <code>accelModifiers</code>
: <code>String</code>  A string listing modifiers that may/must be pressed with the <code>accelKey</code>.  (See accelerator notes section.)
; <code>accessKey</code>
; <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]
: <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]


==== Accelerator Notes ====
==== History ====


The <code>accelKey</code> and <code>accelModifiers</code> are used verbatim for a [https://developer.mozilla.org/en/XUL/key XUL key] element.
In Greasemonkey [[Version history#0.9.2|0.9.2]], this API was changed.
The <code>accelKey</code> is used as the <code>key</code> (when a string) or <code>keycode</code> (when a number) attribute.
Previously, it accepted five parameters including <code>accelKey</code> and <code>accelModifiers</code> which have been removed.
The <code>accelModifiers</code> is used as the <code>modifiers</code> attribute.
See [http://wiki.greasespot.net/index.php?title=GM_registerMenuCommand&oldid=6238 this page's history] for a description of them.
The behavior is as described in [https://developer.mozilla.org/en/XUL/key#Details_on_key.2c_keycode.2c_and_modifiers_attributes Mozilla's documentation for these attributes].
If a script passes all five parameters, in the old style, then the fifth argument is used for <code>accessKey</code>.


== Returns ==
== Returns ==

Revision as of 14:48, 14 April 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, accelKey, accelModifiers, 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, "e", "control", "h");
GM_registerMenuCommand("Hello, world! (again)", hello2, "e", "shift alt", "w");