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= | {{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> | |||
:* 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]]. | |||
[[#Description|top]] | [[#Syntax|back]] | |||
= Examples = | = Examples = | ||
<code> | |||
GM_registerMenuCommand( "Hello, world!", hello, "e", "control", "h" ); | |||
</code> | |||
GM_registerMenuCommand( "Hello world!", | <code> | ||
GM_registerMenuCommand( "Hello, world! (again)", hello2, "e", "shift alt", "w" ); | |||
</code> | |||
GM_registerMenuCommand( "Hello world | <code> | ||
GM_registerMenuCommand( "Hello, world (simple)", helloSimple ); | |||
</code> | |||
[[#Description|top]] | |||
= Notes = | |||
[[Category: | [[#Description|top]] | ||
[[Category:API_Reference|G]] |
Revision as of 23:28, 6 December 2007
Description
This API method allows user scripts to add a menu command to the "User Script Commands" submenu.
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
- All properties and event handlers are optional except commandName and commandFunc.
Properties
commandName
- Value: String
- Usage:
commandName
- Name to display in the "User Script Commands" submenu.
commandFunc
- Value: String
- Usage:
commandFunc = function(){ // Some code };
- Function to call
accelKey
- Value: Object
- Usage:
accelKey = "g";
- A single character or keycode that can trigger the command.
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.
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.
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 );