Select special characters for Memrise quizzes using keyboard shortcuts Ctrl+1 to 0.
当前为
// ==UserScript==
// @name Memrise Easy Quiz Input
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Select special characters for Memrise quizzes using keyboard shortcuts Ctrl+1 to 0.
// @author Cezille07
// @match https://www.memrise.com/course/*
// @grant none
// @license GNU GPLv3
// ==/UserScript==
(function() {
'use strict';
var $ = window.jQuery;
var selector = '.keyboard a.shiny-box';
$(document).ready(function () {
console.log('[MEQI] Initializing Memrize Easy Quiz Input');
var boxes = document.getElementById('boxes');
if (boxes) {
var observer = new MutationObserver(function(mutationRecords) {
var inputs = $(selector);
if (inputs.length) {
console.log('[MEQI] Adding Numbers', inputs);
for (var i = 0; i < inputs.length; i++) {
console.log('Adding help', i, inputs[i]);
inputs[i].innerText = (i + 1) + ': ' + inputs[i].innerText;
}
} else {
console.log('[MEQI] No shortcuts to add hints to');
}
});
observer.observe(boxes, {
childList: true
});
}
});
window.addEventListener('keydown', function (e) {
var inputs = $(selector);
var map = {};
var ZERO = 48;
for (var i = 0; i < 10; i++) {
map[i + ZERO] = i - 1;
}
map[ZERO] = 9;
if (inputs.length > 0 && e.keyCode >= ZERO && e.keyCode < ZERO + 10) {
console.log('[MEQI] Clicking', e.code);
document.activeElement.blur();
setTimeout(function () {
var el = inputs[map[e.keyCode]];
var colIdx = el.innerText.indexOf(': ');
var num = el.innerText.slice(0, colIdx);
el.innerText = el.innerText.slice(colIdx + 2);
el.click();
el.innerText = num + ': ' + el.innerText;
});
}
});
})();