Skip to content

Instantly share code, notes, and snippets.

@TaraRed
Created July 13, 2012 14:50
Show Gist options
  • Save TaraRed/3105302 to your computer and use it in GitHub Desktop.
Save TaraRed/3105302 to your computer and use it in GitHub Desktop.
Allows you to use "1", "2", "3" and "4" to press the review buttons in the review tools.
// ==UserScript==
// @author Tom Wijsman
// @name Review Keyboard
// @description Allows you to use "1", "2", "3" and "4" to press the review buttons in the review tools.
// @include http://*superuser.com/review-beta/*
// ==/UserScript==
function EmbedCodeOnPage(javascript_code) {
var code_element = document.createElement('script');
code_element.type = 'text/javascript';
code_element.textContent = javascript_code;
document.getElementsByTagName('head')[0].appendChild(code_element);
}
function EmbedFunctionOnPageAndExecute(function_contents) {
EmbedCodeOnPage("(" + function_contents.toString() + ")()");
}
EmbedFunctionOnPageAndExecute(function() {
function keyCheck(e)
{
if (e.keyCode >= 49 && e.keyCode <= 52 && $('.comment-form textarea').length === 0)
{
var reviewButton = $('.review-actions').find('input')[e.keyCode - 49];
if (document.createEvent) {
var event = document.createEvent("MouseEvents");
event.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0,
false, false, false, false,
0, null);
reviewButton.dispatchEvent(event);
}
else if (reviewButton.fireEvent) {
reviewButton.fireEvent("onclick");
}
else {
window.alert('Your browser is not supported.');
}
}
}
window.addEventListener('keydown', keyCheck, true);
});
@iglvzx
Copy link

iglvzx commented Jul 14, 2012

Good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment