GM.registerMenuCommand: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
m (Text replace - "Examples | Notes " to "")
(link to other docs)
(20 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:GM_registerMenuCommand}}
As of Greasemonkey 4.0, this method has been removed.
 
* See [https://wiki.greasespot.net/index.php?title=GM_registerMenuCommand&oldid=7473 history] for older versions.
== Description ==
* See the [https://github.com/greasemonkey/gm4-polyfill GM4 Polyfill] for a Greasemonkey 4 compatible way to get similar functionality.
 
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]].
 
== Syntax ==
 
'''GM_registerMenuCommand(''' ''commandName'', ''commandFunc'', ''accelKey'', ''accelModifiers'', ''accessKey'' ''')'''
 
:Value: Function
:Returns: undefined
:Compatibility: [[Version_history#0.2.5|Greasemonkey 0.2.5+]]
 
:{| cellpadding="5" style="border-style:solid; background:#FFFFE0;"
|+ Parameters
!style="background:#CC9900;"|'''Properties''' || style="background:#CC9900;"|'''Event Handlers'''
|-
| <code><span style="background:#FFFFE0;">[[#commandName |commandName]]</span></code> ||<code><span style="background:#FFFFE0;">[[#commandFunc|commandFunc]]</span></code>
|-
|<code><span style="background:#FFFFE0;">[[#accelKey |accelKey]]</span></code>
|-
|<code><span style="background:#FFFFE0;">[[#accelModifiers |accelModifiers]]</span></code>
|-
|<code><span style="background:#FFFFE0;">[[#accessKey |accessKey]]</span></code>
|}
:* All properties and event handlers are optional except [[#commandName|commandName]] and [[#commandFunc|commandFunc]].
 
[[#top|top]]
=== Properties ===
----
==== <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]].
 
[[#top|top]] | [[#Syntax|back]]''
 
==== <code>commandFunc</code> ====
:Value: Function
:Usage: <code>'''commandFunc''' = function(){ ''/* some code */'' };</code>
 
:* Function to call
 
[[#top|top]] | [[#Syntax|back]]
 
==== <code>accelKey</code> ====
:Value: String
:Usage: <code>'''accelKey''' = "g";</code>
 
:* A single character or keycode that can trigger the command.
 
[[#top|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.
 
[[#top|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]].
 
[[#top|top]] | [[#Syntax|back]]
 
== Examples ==
{{Samp |1=<pre style="border: none; margin: inherit;">GM_registerMenuCommand("Hello, world (simple)", helloSimple);</pre>}}
 
{{Samp |1=<pre style="border: none; margin: inherit;">GM_registerMenuCommand("Hello, world!", hello, "e", "control", "h");</pre>}}
 
{{Samp |1=<pre style="border: none; margin: inherit;">GM_registerMenuCommand("Hello, world! (again)", hello2, "e", "shift alt", "w");</pre>}}
 
[[Category:API_Reference|R]]

Revision as of 15:22, 14 November 2017

As of Greasemonkey 4.0, this method has been removed.

  • See history for older versions.
  • See the GM4 Polyfill for a Greasemonkey 4 compatible way to get similar functionality.