Mturk Radio Keybinds

Keybinds to select radios

目前为 2017-02-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Mturk Radio Keybinds
  3. // @namespace https://gist.github.com/Kadauchi
  4. // @version 2.1.0
  5. // @description Keybinds to select radios
  6. // @author Kadauchi
  7. // @icon http://i.imgur.com/oGRQwPN.png
  8. // @include /^https://(www\.mturkcontent|s3\.amazonaws)\.com/
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // ==/UserScript==
  12.  
  13. document.body.insertAdjacentHTML(
  14. `afterbegin`,
  15.  
  16. `<div style="background-color: lightgreen;">` +
  17. `<label style="color: black; margin-left: 10px;">Script: Mturk Radio Keybinds</label>` +
  18. `<span style="margin-left: 3px;cursor:help" title="Press 1 through 9 or z through . to select the radio you want. \n\nPress Enter to submit the HIT. \n\nCheck auto submit to have the HIT submit after you press your keybind.">&#10068;</span>` +
  19.  
  20. `<label style="color: black; float: right; margin-right: 10px;">Auto Submit: ` +
  21. `<input id="autosubmit" type="checkbox" ${GM_getValue(`autosubmit`) ? `checked` : ``}></input>` +
  22. `</label>` +
  23.  
  24. `<label style="color: black; float: right; margin-right: 10px;">Use [z-.]: ` +
  25. `<input id="letters" type="checkbox" ${GM_getValue(`letters`) ? `checked` : ``}></input>` +
  26. `</label>` +
  27.  
  28. `<label style="color: black; float: right; margin-right: 10px;">Use [1-9]: ` +
  29. `<input id="numbers" type="checkbox" ${GM_getValue(`numbers`) ? `checked` : ``}></input>` +
  30. `</label>` +
  31.  
  32. `</div>`
  33. );
  34.  
  35. const numbers = document.getElementById(`numbers`);
  36. const letters = document.getElementById(`letters`);
  37. const autosubmit = document.getElementById(`autosubmit`);
  38.  
  39. numbers.addEventListener(`change`, function (event) {
  40. GM_setValue(`numbers`, numbers.checked);
  41. });
  42.  
  43. letters.addEventListener(`change`, function (event) {
  44. GM_setValue(`letters`, letters.checked);
  45. });
  46.  
  47. autosubmit.addEventListener(`change`, function (event) {
  48. GM_setValue(`autosubmit`, autosubmit.checked);
  49. });
  50.  
  51. window.addEventListener(`keydown`, function (event) {
  52. const key = event.key;
  53.  
  54. if (numbers.checked && key.match(/[1-9]/)) {
  55. const radio = document.querySelectorAll(`[type="radio"]`)[key - 1];
  56. if (radio) radio.click();
  57.  
  58. if (autosubmit.checked) document.querySelector(`[type="submit"]`).click();
  59. }
  60.  
  61. if (letters.checked && key.match(/z|x|c|v|b|n|m|,|./)) {
  62. const convert = { 'z': 0, 'x': 1, 'c': 2, 'v': 3, 'b': 4, 'n': 5, 'm': 6, ',': 7, '.': 8 };
  63. const radio = document.querySelectorAll(`[type="radio"]`)[convert[key]];
  64. if (radio) radio.click();
  65.  
  66. if (autosubmit.checked) document.querySelector(`[type="submit"]`).click();
  67. }
  68.  
  69. if (key.match(/Enter/)) {
  70. document.querySelector(`[type="submit"]`).click();
  71. }
  72. });
  73.  
  74. window.focus();