Images and Sentences HIT Helper

"Relate a phrase to an image (10 questions)". Press 1, 2, or 3 to select options. Press the same key again to hit the next button. (1, 1 selects option one and hits next. 1, 2 ends up selecting option 2 and waiting for you to hit 2).

当前为 2014-10-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Images and Sentences HIT Helper
  3. // @namespace http://ericfraze.com
  4. // @version 0.1
  5. // @description "Relate a phrase to an image (10 questions)". Press 1, 2, or 3 to select options. Press the same key again to hit the next button. (1, 1 selects option one and hits next. 1, 2 ends up selecting option 2 and waiting for you to hit 2).
  6. // @author Eric Fraze
  7. // @match https://web.engr.illinois.edu/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. $(document).ready(function() {
  13. $(document).keyup(function (event) {
  14. var key = toCharacter(event.keyCode);
  15. if (key=='1'){
  16. if ($("#draw").prop("checked")) {
  17. nextQuestion();
  18. }else{
  19. $("#draw").prop("checked", true);
  20. }
  21. }
  22. if (key=='2'){
  23. if ($("#scene").prop("checked")) {
  24. nextQuestion();
  25. }else{
  26. $("#scene").prop("checked", true);
  27. }
  28. }
  29. if (key=='3'){
  30. if ($("#nodraw").prop("checked")) {
  31. nextQuestion();
  32. }else{
  33. $("#nodraw").prop("checked", true);
  34. }
  35. }
  36. });
  37. });
  38.  
  39. function toCharacter(keyCode) {
  40.  
  41. // delta to convert num-pad key codes to QWERTY codes.
  42. var numPadToKeyPadDelta = 48;
  43.  
  44. // if a numeric key on the num pad was pressed.
  45. if (keyCode >= 96 && keyCode <= 105) {
  46. keyCode = keyCode - numPadToKeyPadDelta;
  47. return String.fromCharCode(keyCode);
  48. }
  49.  
  50. if (keyCode == 106)
  51. return "*";
  52.  
  53. if (keyCode == 107)
  54. return "+";
  55.  
  56. if (keyCode == 109)
  57. return "-";
  58.  
  59. if (keyCode == 110)
  60. return ".";
  61.  
  62. if (keyCode == 111)
  63. return "/";
  64.  
  65. // the 'Enter' key was pressed
  66. if (keyCode == 13)
  67. return "="; //TODO: you should change this to interpret the 'Enter' key as needed by your app.
  68.  
  69. return String.fromCharCode(keyCode);
  70. }