Created
July 13, 2012 14:50
-
-
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.
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== | |
// @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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good idea!