GM.registerMenuCommand: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m Text replace - "</pre>}}" to "</pre>"
simplify
Line 3: Line 3:
== Description ==
== Description ==


This [[API_reference|API]] method allows user scripts to add a menu command to the [[Greasemonkey_Manual:Monkey_Menu#The_Menu|"User Script Commands" submenu]].
This method allows user scripts to add an item the [[Greasemonkey_Manual:Monkey_Menu#The_Menu|User Script Commands]] menu.
 
Compatibility: [[Version_history#0.2.5|Greasemonkey 0.2.5+]]


== Syntax ==
== Syntax ==


'''GM_registerMenuCommand(''' ''commandName'', ''commandFunc'', ''accelKey'', ''accelModifiers'', ''accessKey'' ''')'''
{{Function|GM_registerMenuCommand|caption, commandFunc, accelKey, accelModifiers, accessKey}}


:Value: Function
=== Arguments ===
:Returns: undefined
:Compatibility: [[Version_history#0.2.5|Greasemonkey 0.2.5+]]


:{| cellpadding="5" style="border-style:solid; background:#FFFFE0;"
; <code>caption</code>
|+ Parameters
: <code>String</code> The caption to display on the menu item.
!style="background:#CC9900;"|'''Properties''' || style="background:#CC9900;"|'''Event Handlers'''
; <code>commandFunc</code>
|-
: <code>Function</code> The function to call when this menu item is selected by the user.
| <code><span style="background:#FFFFE0;">[[#commandName |commandName]]</span></code> ||<code><span style="background:#FFFFE0;">[[#commandFunc|commandFunc]]</span></code>
; <code>accelKey</code>
|-
: <code>String</code> '''Details/verification needed!''' A single character or keycode that can trigger the command.
|<code><span style="background:#FFFFE0;">[[#accelKey |accelKey]]</span></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><span style="background:#FFFFE0;">[[#accelModifiers |accelModifiers]]</span></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><span style="background:#FFFFE0;">[[#accessKey |accessKey]]</span></code>
|}
:* All properties and event handlers are optional except [[#commandName|commandName]] and [[#commandFunc|commandFunc]].


=== Properties ===
== Returns ==
----
==== <code>commandName</code> ====
:Value: String
:Usage: <code>'''commandName''' = "Some Name";</code>
 
:* Name to display in the [[Greasemonkey_Manual:Monkey_Menu#The_Menu|"User Script Commands" submenu]].
 
 
==== <code>commandFunc</code> ====
:Value: Function
:Usage: <code>'''commandFunc''' = function(){ ''/* some code */'' };</code>
 
:* Function to call


<code>undefined</code>


== Examples ==


==== <code>accelKey</code> ====
:Value: String
:Usage: <code>'''accelKey''' = "g";</code>
:* A single character or keycode that can trigger the command.
==== <code>accelModifiers</code> ====
:Value: String
:Usage: <code>'''accelModifiers''' = "control alt";</code>
:* A string listing modifiers that must be pressed with the [[#accelKey|accelKey]]. If there's more than one, then they should be separated with spaces. Available modifiers are: shift, alt, meta, control, and accel.
==== <code>accessKey</code> ====
:Value: String
:Usage: <code>'''accessKey''' = "g";</code>
:* A single character that can be used to jump to the command when the menu is open. It should be a letter in [[#commandName|commandName]].
== Examples ==
<pre class='sample'>GM_registerMenuCommand("Hello, world (simple)", helloSimple);</pre>
<pre class='sample'>GM_registerMenuCommand("Hello, world (simple)", helloSimple);</pre>



Revision as of 22:49, 8 February 2010


Description

This method allows user scripts to add an item 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 Details/verification needed! A single character or keycode that can trigger the command.
accelModifiers
String Details/verification needed! A string listing modifiers that must be pressed with the accelKey. If there's more than one, then they should be separated with spaces. Available modifiers are: shift, alt, meta, control, and accel.
accessKey
String 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 caption.

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