Skip to content

Instantly share code, notes, and snippets.

@felixvd
Forked from hsperr/matecat_hotkey.js
Last active November 10, 2020 13:33
Show Gist options
  • Save felixvd/413883a71808bc706d35 to your computer and use it in GitHub Desktop.
Save felixvd/413883a71808bc706d35 to your computer and use it in GitHub Desktop.
Greasemonkey/Tampermonkey script to add hotkeys to the Review mode of Matecat.
//Author: Henning Sperr <henning.sperr@gmail.com>
// 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;
}
}
});
@tahirsanli
Copy link

this is very helpful. but how do we integrate / make use of that code? pardon my newbie question..

@felixvd
Copy link
Author

felixvd commented Oct 16, 2020

I guess you would install the Greasemonkey extension, add this script, and then hope that the website has changed so little that this 5-year-old code still works. I can't be of help beyond that, sorry.

@tahirsanli
Copy link

tahirsanli commented Nov 10, 2020

Thanks for taking the time to answer. Cheers!

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