GM.registerMenuCommand: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(→‎Description: https://www.irctc.co.in/cgi-bin/bv60.dll/irctc/booking/bookticket.do?click=true)
(link to other docs)
(9 intermediate revisions by 4 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+]]
 
 
  </b><div style="">
<select name="day" class="formText0">
 
<option value="0">Day</option>
 
 
<option value="01">01</option>
 
<option value="02">02</option>
 
<option value="03">03</option>
 
<option value="04">04</option>
 
<option value="05">05</option>
 
<option value="06">06</option>
 
<option value="07">07</option>
 
<option value="08">08</option>
 
<option value="09">09</option>
 
<option value="10">10</option>
 
<option value="11">11</option>
 
<option value="12">12</option>
 
<option value="13">13</option>
 
<option value="14">14</option>
 
<option value="15">15</option>
 
<option value="16">16</option>
 
<option value="17">17</option>
 
<option value="18">18</option>
 
<option value="19">19</option>
 
<option value="20">20</option>
 
<option value="21">21</option>
 
<option value="22">22</option>
 
<option value="23">23</option>
 
<option value="24">24</option>
 
<option value="25">25</option>
 
<option value="26">26</option>
 
<option value="27">27</option>
 
<option value="28">28</option>
 
<option value="29">29</option>
 
<option value="30">30</option>
 
<option value="31">31</option>
 
</select>
 
<b> </b></div>
 
 
<script language="JavaScript">
if(document.forms[0].day.value==0)
{
if(document.forms[0].CurrentDate.value<10)
document.forms[0].day.value = 0+document.forms[0].CurrentDate.value;
else
document.forms[0].day.value = document.forms[0].CurrentDate.value;
}
</script>
 
 
 
 
<b>    </b><div style="">
<b> <select name="month" class="formText0">
 
<option value="0">Month</option>
 
 
<option value="1">Jan</option>
 
<option value="2">Feb</option>
 
<option value="3">Mar</option>
 
<option value="4">Apr</option>
 
<option value="5">May</option>
 
<option value="6">Jun</option>
 
<option value="7">Jul</option>
 
<option value="8">Aug</option>
 
<option value="9">Sep</option>
 
<option value="10">Oct</option>
 
<option value="11">Nov</option>
 
<option value="12">Dec</option>
 
</select>
 
</b></div>
 
 
 
 
<script language="JavaScript">
if(document.forms[0].month.value==0)
{
document.forms[0].month.value = parseInt(document.forms[0].CurrentMonth.value)+1;
}
</script>
 
 
 
 
<b> </b><div style="">
<select name="year" class="formText0">
 
<option value="0">Year</option>
 
 
<option value="2011">2011</option>
 
</select></div></td>
 
== 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>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 ====
 
In Greasemonkey [[Version history#0.9.2|0.9.2]], this API was changed.
Previously, it accepted five parameters including <code>accelKey</code> and <code>accelModifiers</code> which have been removed.
See [http://wiki.greasespot.net/index.php?title=GM_registerMenuCommand&oldid=6238 this page's history] for a description of them.
If a script passes all five parameters, in the old style, then the fifth argument is used for <code>accessKey</code>.
 
== 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]]
 
== See Also ==
 
The [[GM_config]] <code>@require</code> library can handle many of the tasks that <code>GM_registerMenuCommand</code> is otherwise used for, in a more user-friendly manner.

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.