Skip to content

Instantly share code, notes, and snippets.

@mctrafik
Created May 1, 2020 05:58
Show Gist options
  • Save mctrafik/d78af59bbe00ec68eab2c451b95736aa to your computer and use it in GitHub Desktop.
Save mctrafik/d78af59bbe00ec68eab2c451b95736aa to your computer and use it in GitHub Desktop.
Zooniverse Zoo-Keeper Shortcuts.
function addHints() {
document.querySelectorAll('label.answer p').forEach((p, i) => {
if (p.getAttribute('data-processed')) return;
let hint = document.createTextNode(` (SHIFT: ${i + 1})`);
p.appendChild(hint);
p.setAttribute('data-processed', 'true');
});
}
setInterval(addHints, 1000);
window.addEventListener('keydown', (k) => {
if (!k.shiftKey) return;
if (k.code.indexOf('Digit') === 0) {
/* Actually select an option. */
let numeral = k.keyCode - 48;
document.querySelector(`label.answer:nth-child(${numeral}) input`).click();
setTimeout(() => {
let buttons = document.querySelectorAll('nav.task-nav button');
if (!buttons.length) return;
buttons[buttons.length - 1].focus();
}, 100);
} else {
/* Else display options */
adddHints();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment