GM.registerMenuCommand: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(→‎Description: Changed "ctrl alt" to "control alt")
(Symmetry update (Hope everyone likes it :))
Line 1: Line 1:
{{underscore|title=GM_registerMenuCommand}}
{{underscore|title=GM_xmlhttpRequest}}
__NOTOC__


= Syntax =
== 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]].
 
[[#Examples|Examples]] | [[#Notes|Notes]]
 
== Syntax ==


'''GM_registerMenuCommand(''' ''commandName'', ''commandFunc'', ''accelKey'', ''accelModifiers'', ''accessKey'' ''')'''
'''GM_registerMenuCommand(''' ''commandName'', ''commandFunc'', ''accelKey'', ''accelModifiers'', ''accessKey'' ''')'''


= Description =
:Returns: Nothing, details Object
:Compatibility: Greasemonkey 0.2.5+
 
:{| border="1" cellpadding="5"
|+ Parameters
!|'''Properties''' || !|'''Event Handlers'''
|-
| <code>[[#commandName |commandName]]</code> ||<code>[[#commandFunc|commandFunc]]</code>
|-
|<code>[[#accelKey |accelKey]]</code>
|-
|<code>[[#accelModifiers |accelModifiers]]</code>
|-
|<code>[[#accessKey |accessKey]]</code>
|}
:* All properties and event handlers are optional except [[#commandName|commandName]] and [[#commandFunc|commandFunc]].
 
[[#Description|top]]
=== Properties ===
----
==== <code>commandName</code> ====
:Value: String
:Usage: <code>commandName</code>
 
:* Name to display in the [[Greasemonkey_Manual:Monkey_Menu#The_Menu|"User Script Commands" submenu]].
 
[[#Description|top]] | [[#Syntax|back]]''
 
==== <code>commandFunc</code> ====
:Value: String
:Usage: <code>commandFunc = function(){ ''// Some code'' };</code>
 
:* Function to call
 
[[#Description|top]] | [[#Syntax|back]]
 
==== <code>accelKey</code> ====
:Value: Object
:Usage: <code>accelKey = "g";</code>
 
:* A single character or keycode that can trigger the command.
 
[[#Description|top]] | [[#Syntax|back]]
 
==== <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.
 
[[#Description|top]] | [[#Syntax|back]]
 
==== <code>accessKey</code> ====
:Value: String
:Usage: <code>accessKey = "g";</code>


Userscripts can call GM_registerMenuCommand to add a menu command to the "User Script Commands" submenu.
:* 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]].
The first two arguments are required; the others are optional.


; commandName : Name to display in the menu
[[#Description|top]] | [[#Syntax|back]]
; commandFunc : Function to call
; accelKey : A single character (e.g. 'g') or keycode that can trigger the command
; accelModifiers: A string listing modifiers that must be pressed with the accelKey. If there's more than one, then they should be separated with spaces. For example, <code>'shift'</code> or <code>'control alt'</code>. Available modifiers are: shift, alt, meta, control, and accel.
; accessKey : A single character (e.g. 'g') that can be used to jump to the command when the menu is open. It should be a letter in commandName


= Examples =
= Examples =
<code>
GM_registerMenuCommand( "Hello, world!", hello, "e", "control", "h" );
</code>


  GM_registerMenuCommand( "Hello world!", hello, "e", "control", "h" );
<code>
  GM_registerMenuCommand( "Hello, world! (again)", hello2, "e", "shift alt", "w" );
</code>


  GM_registerMenuCommand( "Hello world! (again)", hello2, "e", "shift alt", "w" );
<code>
  GM_registerMenuCommand( "Hello, world (simple)", helloSimple );
</code>


GM_registerMenuCommand( "Hello world (simple)", helloSimple );
[[#Description|top]]


= Notes =


[[Category:API Reference|R]]
[[#Description|top]]
[[Category:API_Reference|G]]

Revision as of 23:28, 6 December 2007

Template:Underscore


Description

This API method allows user scripts to add a menu command to the "User Script Commands" submenu.

Examples | Notes

Syntax

GM_registerMenuCommand( commandName, commandFunc, accelKey, accelModifiers, accessKey )

Returns: Nothing, details Object
Compatibility: Greasemonkey 0.2.5+
Parameters
Properties Event Handlers
commandName commandFunc
accelKey
accelModifiers
accessKey

top

Properties


commandName

Value: String
Usage: commandName

top | back

commandFunc

Value: String
Usage: commandFunc = function(){ // Some code };
  • Function to call

top | back

accelKey

Value: Object
Usage: accelKey = "g";
  • A single character or keycode that can trigger the command.

top | back

accelModifiers

Value: String
Usage: accelModifiers = "control alt";
  • 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.

top | back

accessKey

Value: String
Usage: accessKey = "g";
  • A single character that can be used to jump to the command when the menu is open. It should be a letter in commandName.

top | back

Examples

GM_registerMenuCommand( "Hello, world!", hello, "e", "control", "h" );

GM_registerMenuCommand( "Hello, world! (again)", hello2, "e", "shift alt", "w" );

GM_registerMenuCommand( "Hello, world (simple)", helloSimple );

top

Notes

top