-
-
Save felixvd/413883a71808bc706d35 to your computer and use it in GitHub Desktop.
Greasemonkey/Tampermonkey script to add hotkeys to the Review mode of Matecat.
This file contains hidden or 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
//Author: Henning Sperr <[email protected]> | |
// License: BSD 3 clause | |
// ==UserScript== | |
// @name Matecat Review Hotkeys | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description try to take over the world! | |
// @author Henning Sperr | |
// @match https://*.matecat.com/revise/* | |
// @grant none | |
// ==/UserScript== | |
// This is pretty hacky way to access the elements but for the task its good enough | |
// Greasemonkey/Tampermonkey script to add hotkeys to the Review mode of Matecat. | |
// Ctrl+(1-5) increases the error value of each type of issue, i.e. the radio button selection is shifted one to the right. | |
// Perfect for keeping your hands on the keyboard while reviewing. | |
function isDescendant(parent, child) { | |
var node = child.parentNode; | |
while (node != null) { | |
if (node == parent) { | |
return true; | |
} | |
node = node.parentNode; | |
} | |
return false; | |
} | |
// Your code here... | |
$(document).keydown(function(e) { | |
//49-54 is 1, 2, 3, 4, 5 keys as much as we have radio buttons | |
if(e.which >= 49 && e.which < 54 && e.ctrlKey ) { | |
// ctrl+1 pressed | |
var editor = document.getElementsByClassName("editor"); | |
console.log(editor[0]); | |
var radios = document.getElementsByName('t'+(e.which-48)); | |
var realRadios = [] | |
for(var i=0; i<radios.length;i++){ | |
if(isDescendant(editor[0], radios[i])){ | |
realRadios[realRadios.length] = radios[i]; | |
} | |
} | |
console.log(realRadios) | |
if(realRadios[0].checked) { | |
console.log(1) | |
realRadios[0].checked = false; | |
realRadios[1].checked = true; | |
} else if (realRadios[1].checked) { | |
console.log(2) | |
realRadios[1].checked = false; | |
realRadios[2].checked = true; | |
} else if (realRadios[2].checked) { | |
console.log(3) | |
realRadios[0].checked = true; | |
realRadios[2].checked = false; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for taking the time to answer. Cheers!