GM.registerMenuCommand: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(→‎Arguments: documentation, mostly as links to the underlying Mozilla attributes)
(link to other docs)
(12 intermediate revisions by 5 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 method allows user scripts to add an item to the [[Greasemonkey_Manual:Monkey_Menu#The_Menu|User Script Commands]] menu.
 
Compatibility: [[Version_history#0.2.5|Greasemonkey 0.2.5+]]
 
== Syntax ==
 
{{Function|GM_registerMenuCommand|caption, commandFunc, accelKey, accelModifiers, accessKey}}
 
=== Arguments ===
 
; <code>caption</code>
: <code>String</code> The caption to display on the menu item.
; <code>commandFunc</code>
: <code>Function</code> The function to call when this menu item is selected by the user.
; <code>accelKey</code>
: <code>String</code> or <codeNumber</code> A single character or keycode that can trigger the command.  (See accelerator notes section.)
; <code>accelModifiers</code>
: <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>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 ==
 
<code>undefined</code>
 
== Examples ==
 
<pre class='sample'>GM_registerMenuCommand("Hello, world (simple)", helloSimple);</pre>
 
<pre class='sample'>GM_registerMenuCommand("Hello, world!", hello, "e", "control", "h");</pre>
 
<pre class='sample'>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.