Greasy Fork 还支持 简体中文。

GC - Pick Your Own - Keyboard Controls

Add keyboard navigation to GC's Pick Your Own.

  1. // ==UserScript==
  2. // @name GC - Pick Your Own - Keyboard Controls
  3. // @namespace https://greasyfork.org/en/users/1175371
  4. // @version 0.4
  5. // @description Add keyboard navigation to GC's Pick Your Own.
  6. // @author sanjix
  7. // @match https://www.grundos.cafe/medieval/pickyourown/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=grundos.cafe
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. var start = document.querySelector('input[value="Click to Play!"]');
  14. var left = document.querySelector('input#pyo-left-arrow');
  15. var right = document.querySelector('input#pyo-right-arrow');
  16. var up = document.querySelector('input#pyo-up-arrow');
  17. var down = document.querySelector('input#pyo-down-arrow');
  18. var map = document.querySelector('form[action="/medieval/process_pickyourown/?pick=1"] input[type="image"]');
  19. var collect = document.querySelector('input[value="Collect Berries and Leave Farm"]');
  20.  
  21. document.addEventListener("keydown", ((event) => {
  22. switch (event.keyCode) {
  23. case 38: //up-arrow
  24. case 87: //w
  25. {
  26. if (up != null) {
  27. event.preventDefault();
  28. up.click();
  29. }
  30. }
  31. break;
  32. case 37: //left-arrow
  33. case 65: //a
  34. {
  35. if (left != null) {
  36. event.preventDefault();
  37. left.click();
  38. }
  39. }
  40. break;
  41. case 40: //down-arrow
  42. case 83: //s
  43. {
  44. if (down != null) {
  45. event.preventDefault();
  46. down.click();
  47. }
  48. }
  49. break;
  50. case 39: //right-arrow
  51. case 68: //d
  52. {
  53. if (right != null) {
  54. event.preventDefault();
  55. right.click();
  56. }
  57. }
  58. break;
  59. case 13: //enter
  60. {
  61. if (start != null) {
  62. start.click();
  63. } else if (map != null) {
  64. map.click();
  65. } else if (collect != null) {
  66. collect.click();
  67. }
  68. }
  69. break;
  70. }
  71. }));