Difference between revisions of "GM.registerMenuCommand"

From GreaseSpot Wiki
Jump to navigationJump to search
(→‎Description: corrected typo)
(→‎Arguments: documentation, mostly as links to the underlying Mozilla attributes)
Line 18: Line 18:
: <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>accelKey</code>
: <code>String</code> '''Details/verification needed!''' A single character or keycode that can trigger the command.
: <code>String</code> or <codeNumber</code> A single character or keycode that can trigger the command. (See accelerator notes section.)
; <code>accelModifiers</code>
; <code>accelModifiers</code>
: <code>String</code>  '''Details/verification needed!''' A string listing modifiers that must be pressed with the <code>accelKey</code>. If there's more than one, then they should be separated with spaces. Available modifiers are: shift, alt, meta, control, and accel.
: <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> '''Details/verification needed!''' A single character that can be used to jump to the command when the menu is open. It should be a letter in the <code>caption</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]
 
==== Accelerator Notes ====
 
The <code>accelKey</code> and <code>accelModifiers</code> are used verbatim for a [https://developer.mozilla.org/en/XUL/key XUL key] element.
The <code>accelKey</code> is used as the <code>key</code> (when a string) or <code>keycode</code> (when a number) attribute.
The <code>accelModifiers</code> is used as the <code>modifiers</code> attribute.
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].


== Returns ==
== Returns ==

Revision as of 17:34, 26 March 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.
accelKey
String or <codeNumber A single character or keycode that can trigger the command. (See accelerator notes section.)
accelModifiers
String A string listing modifiers that may/must be pressed with the accelKey. (See accelerator notes section.)
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]

Accelerator Notes

The accelKey and accelModifiers are used verbatim for a XUL key element. The accelKey is used as the key (when a string) or keycode (when a number) attribute. The accelModifiers is used as the modifiers attribute. The behavior is as described in Mozilla's documentation for these attributes.

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");