GoComics control with arrow keys

Use arrow keys to go back and forth on comics on GoComics, long press to go to first/last comic

目前为 2024-09-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name GoComics control with arrow keys
  3. // @namespace https://github.com/AbdurazaaqMohammed/userscripts
  4. // @version 1.1
  5. // @description Use arrow keys to go back and forth on comics on GoComics, long press to go to first/last comic
  6. // @author Abdurazaaq Mohammed
  7. // @license The Unlicense
  8. // @homepage https://github.com/AbdurazaaqMohammed/userscripts
  9. // @supportURL https://github.com/AbdurazaaqMohammed/userscripts/issues
  10. // @match https://www.gocomics.com/*
  11. // @run-at document-start
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. let leftPressTimer, rightPressTimer;
  19.  
  20. document.addEventListener('keydown', function(e) {
  21. const key = e.key;
  22.  
  23. if (key === "ArrowLeft") {
  24. leftPressTimer = setTimeout(function() {
  25. const fastBackward = document.querySelector('a.fa.btn.btn-outline-secondary.btn-circle.fa.fa-backward.sm');
  26. if (fastBackward && fastBackward.href !== window.location.href) {
  27. fastBackward.click(); // Fast backward on long press
  28. }
  29. }, 500); // 500ms delay for long press detection
  30.  
  31. } else if (key === "ArrowRight") {
  32. rightPressTimer = setTimeout(function() {
  33. const fastForward = document.querySelector('a.fa.btn.btn-outline-secondary.btn-circle.fa-forward.sm');
  34. if (fastForward && fastForward.href !== window.location.href) {
  35. fastForward.click(); // Fast forward on long press
  36. }
  37. }, 500); // 500ms delay for long press detection
  38. }
  39. });
  40.  
  41. document.addEventListener('keyup', function(e) {
  42. const key = e.key;
  43.  
  44. if (key === "ArrowLeft") {
  45. clearTimeout(leftPressTimer);
  46. const previous = document.querySelector('.js-previous-comic.sm.fa-caret-left.btn-circle.btn-outline-secondary.btn.fa');
  47. if (previous && previous.href !== window.location.href) {
  48. previous.click(); // Go to previous comic release if href is different
  49. }
  50. } else if (key === "ArrowRight") {
  51. clearTimeout(rightPressTimer);
  52. const next = document.querySelector('.sm.fa-caret-right.btn-circle.btn-outline-secondary.btn.fa');
  53. if (next && next.href !== window.location.href) {
  54. next.click(); // Go to next comic release if href is different
  55. }
  56. }
  57. });
  58. })();