Skip to content

Instantly share code, notes, and snippets.

@ptbrowne
Created May 10, 2016 13:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptbrowne/167b192fb169dcb027b07032cbeb9c7f to your computer and use it in GitHub Desktop.
Save ptbrowne/167b192fb169dcb027b07032cbeb9c7f to your computer and use it in GitHub Desktop.
Ornikar Keyboard shortcuts
// ==UserScript==
// @name Ornikar Keyboard Shortcuts
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add ABCD shortcuts to Ornikar questions
// @author Patrick Browne
// @match https://www.ornikar.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var authorizedLetters = 'abcd';
var click = function (node) {
var ev = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
node.dispatchEvent(ev);
};
var clearAll = function (ev) {
ev.preventDefault();
var selected = [].slice.call(document.querySelectorAll('.btn-series.selected'));
for (var i = 0; i < selected.length; i++) {
click(selected[i]);
}
};
document.addEventListener('keyup', function (ev) {
var letter = String.fromCharCode(ev.which).toLowerCase();
if (authorizedLetters.indexOf(letter) > -1) {
var node = document.querySelector('#answer-' + letter);
if (node) { click(node); }
}
if (ev.which == 8) {
clearAll(ev);
}
});
console.info('Tampermonkey Ornikar Keyboard Shortcuts is active');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment