Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
GM_registerMenuCommand() accelerator tester
// ==UserScript==
// @name GM_registerMenuCommand() accelerator tester
// @namespace
// @description A flexible test script for examining if/how GM_rmc's accelerator keys work
// @include about:blank#GM_rmc
// @resource 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;
'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);
<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>Accelerator key:</td>
<td><input type="text" size="1" maxlength="1" id="accelerator"></td>
<td><button id="register">Register this menu command</button></td>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.