// ==UserScript== // @name Mturk Radio Keybinds // @namespace https://gist.github.com/Kadauchi // @version 2.1.4 // @description Keybinds to select radios // @author Kadauchi // @icon http://i.imgur.com/oGRQwPN.png // @include /^https://(www\.mturkcontent|s3\.amazonaws)\.com/ // @grant GM_getValue // @grant GM_setValue // @downloadURL https://update.greasyfork.icu/scripts/24650/Mturk%20Radio%20Keybinds.user.js // @updateURL https://update.greasyfork.icu/scripts/24650/Mturk%20Radio%20Keybinds.meta.js // ==/UserScript== if (document.querySelector(`[type="radio"]`).length === 0) return; document.body.insertAdjacentHTML( `afterbegin`, `
` + `` + `` + `` + `` + `` + `
` ); const numbers = document.getElementById(`numbers`); const letters = document.getElementById(`letters`); const autosubmit = document.getElementById(`autosubmit`); numbers.addEventListener(`change`, e => GM_setValue(`numbers`, numbers.checked)); letters.addEventListener(`change`, e => GM_setValue(`letters`, letters.checked)); autosubmit.addEventListener(`change`, e => GM_setValue(`autosubmit`, autosubmit.checked)); window.addEventListener(`keydown`, e => { const key = e.key; if (key.length === 1) { if (numbers.checked && key.match(/[0-9]/)) { const radio = document.querySelectorAll(`[type="radio"]`)[key !== 0 ? key - 1 : 9]; if (radio) radio.click(); if (autosubmit.checked) document.querySelector(`[type="submit"]`).click(); } if (letters.checked && key.match(/z|x|c|v|b|n|m|,|\.|\//)) { const convert = { 'z': 0, 'x': 1, 'c': 2, 'v': 3, 'b': 4, 'n': 5, 'm': 6, ',': 7, '.': 8, '/': 9 }; const radio = document.querySelectorAll(`[type="radio"]`)[convert[key]]; if (radio) radio.click(); if (autosubmit.checked) document.querySelector(`[type="submit"]`).click(); } } if (key === `Enter`) { document.querySelector(`[type="submit"]`).click(); } }); window.focus();