Skip to content

Instantly share code, notes, and snippets.

@hsperr
Last active March 27, 2023 02:30
Show Gist options
  • Save hsperr/81a5fda8bcea7dcce69a to your computer and use it in GitHub Desktop.
Save hsperr/81a5fda8bcea7dcce69a 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>,
// Felix von Drigalski <fvdrigalski@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");
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];
}
}
if(realRadios[0].checked) {
realRadios[0].checked = false;
realRadios[1].checked = true;
} else if (realRadios[1].checked) {
realRadios[1].checked = false;
realRadios[2].checked = true;
} else if (realRadios[2].checked) {
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