GM.registerMenuCommand: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(link to other docs)
(underscore to dot, 4.x style API, in examples)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
As of Greasemonkey 4.0, this method has been removed.
== Description ==
* See [https://wiki.greasespot.net/index.php?title=GM_registerMenuCommand&oldid=7473 history] for older versions. 
 
* 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#4.11|Greasemonkey 4.11+]]
 
== Syntax ==
 
{{Function|GM.registerMenuCommand|caption, commandFunc, 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>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]
 
==== History ====
 
This method existed in a similar but different form before Greasemonkey 4.0.
 
== Returns ==
 
<code>undefined</code>
 
== Examples ==
 
<pre class='sample'>GM.registerMenuCommand("Hello, world (simple)", () => alert("Hello, world!"));</pre>
 
<pre class='sample'>function hello() { ... }
GM.registerMenuCommand("Hello, world!", hello, "h");</pre>
 
[[Category:API_Reference|R]]
 
== See Also ==
 
The [[GM_config]] <code>@require</code> library is frequently used with <code>GM.registerMenuCommand</code>.

Latest revision as of 14:45, 17 August 2022

Description

This method allows user scripts to add an item to the User Script Commands menu.

Compatibility: Greasemonkey 4.11+

Syntax

function GM.registerMenuCommand( caption, commandFunc, 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.
accessKey
String A single character that can be used to select command when the menu is open. It should be a letter in the caption. [1]

History

This method existed in a similar but different form before Greasemonkey 4.0.

Returns

undefined

Examples

GM.registerMenuCommand("Hello, world (simple)", () => alert("Hello, world!"));
function hello() { ... }
GM.registerMenuCommand("Hello, world!", hello, "h");

See Also

The GM_config @require library is frequently used with GM.registerMenuCommand.