Skip to content
Create a gist now

Instantly share code, notes, and snippets.

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
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
Something went wrong with that request. Please try again.