GM_registerMenuCommand() accelerator tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment