public
Last active

GM_registerMenuCommand() accelerator tester

  • Download Gist
gm-rmc-accelerator-tester.user.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
// ==UserScript==
// @name GM_registerMenuCommand() accelerator tester
// @namespace http://arantius.com/misc/greasemonkey/
// @description A flexible test script for examining if/how GM_rmc's accelerator keys work
// @include about:blank#GM_rmc
// @resource ui.html https://gist.github.com/raw/898642/ui.html
// ==/UserScript==
 
var windowId = String(Math.random()).substr(2);
 
document.body.innerHTML = 'Window ID: '+ windowId
+ GM_getResourceText('ui.html');
 
var registerButtonEl = document.getElementById('register');
var modifiersContEl = document.getElementById('modifiers');
var acceleratorEl = document.getElementById('accelerator');
 
registerButtonEl.addEventListener('click', function() {
var modifiers = [];
var inputs = modifiersContEl.getElementsByTagName('input');
for (var i = 0, input = null; input = inputs[i]; i++) {
if (input.checked) modifiers.push(input.value);
}
var accelerator = acceleratorEl.value;
GM_registerMenuCommand(
'Menu Command w/ accelerator: ' + accelerator + '+' + modifiers.join('+'),
function() {
alert('You pressed ' + accelerator + '+' + modifiers.join('+')
+ '\nIn window: ' + windowId);
},
accelerator, modifiers.join(' '),
accelerator // re-use for access key
);
}, false);
ui.html
HTML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
<br>
<br>
<table>
<tr>
<td valign="top">Modifiers:</td>
<td id="modifiers">
<input type="checkbox" value="shift"> Shift<br>
<input type="checkbox" value="alt"> Alt<br>
<input type="checkbox" value="meta"> Meta<br>
<input type="checkbox" value="control"> Control<br>
<input type="checkbox" value="accel"> Accel<br>
<input type="checkbox" value="access"> Access<br>
<input type="checkbox" value="any"> Any<br>
</td>
</tr>
<tr>
<td>Accelerator key:</td>
<td><input type="text" size="1" maxlength="1" id="accelerator"></td>
</tr>
<tr>
<td></td>
<td><button id="register">Register this menu command</button></td>
</tr>
</table>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.