Arrow Keys Flip Pages

Trigger Pages Flips with custom arrow key shortcuts

当前为 2025-05-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Arrow Keys Flip Pages
  3. // @namespace https://4kliksAlex.github.com/
  4. // @version v0.2.5
  5. // @description Trigger Pages Flips with custom arrow key shortcuts
  6. // @author 4kliksAlex
  7. // @match *://*.oracle.com/javase/tutorial/*
  8. // @match *://*.leetcode.*/leetbook/read/*
  9. // @match *://www.zhipin.com/web/geek/resumeAnalyze**
  10. // @match *://docs.spring.io/**
  11. // @match *://dev.mysql.com/doc/refman/**
  12. // @icon https://upload.wikimedia.org/wikipedia/commons/c/c7/Computer_keyboard_German-key-4.svg
  13. // @grant none
  14. // @license GPLv3
  15. // ==/UserScript==
  16.  
  17. (function () {
  18. "use strict";
  19.  
  20. const selectors = {
  21. "*://*.oracle.com/javase/tutorial/*": {
  22. ArrowLeft: "body > div.MainFlow_wide > div:nth-child(6) > a:nth-child(1)",
  23. ArrowRight: "body > div.MainFlow_wide > div:nth-child(6) > a:nth-child(3)"
  24. },
  25. "*://*.leetcode.*/leetbook/read/*": {
  26. ArrowLeft: "#lc-home > div > div.css-17lel75-layer1-Container.e19m4yof0 > div.css-1qeh80o-MainContainer.e19m4yof1 > div.css-op50bu-ContentLayoutContainer.e1t6ajs0 > div > div.css-1p8jlme-ContentContainer.e12hyigg1 > div:nth-child(4) > div.css-ob1q0v-Container.elt4qmr0 > a:nth-child(1)",
  27. ArrowRight: "#lc-home > div > div.css-17lel75-layer1-Container.e19m4yof0 > div.css-1qeh80o-MainContainer.e19m4yof1 > div.css-op50bu-ContentLayoutContainer.e1t6ajs0 > div > div.css-1p8jlme-ContentContainer.e12hyigg1 > div:nth-child(4) > div.css-ob1q0v-Container.elt4qmr0 > a:nth-child(2)"
  28. },
  29. "*://docs.spring.io/**": {
  30. ArrowLeft: "body > div.body > main > div.content > article > nav > span.prev > a",
  31. ArrowRight: "body > div.body > main > div.content > article > nav > span.next > a"
  32. },
  33. "*://www.zhipin.com/web/geek/resumeAnalyze**": {
  34. ArrowRight: "#wrap > div.resume-analyze > div > div.main-content > div.resume-box > div.resume-item.resume-history > div > form > div.resume-analyze-btns > button.btn.btn-outlint"
  35. },
  36. "*://dev.mysql.com/doc/refman/**": {
  37. ArrowLeft: "#docs-in-page-nav > a:nth-child(1)",
  38. ArrowRight: "#docs-in-page-nav > a:nth-child(4)"
  39. }
  40. };
  41.  
  42. function getSelectorsForCurrentURL() {
  43. const url = window.location.href;
  44. for (const pattern in selectors) {
  45. const urlPattern = new URLPattern(pattern, {
  46. ignoreCase: true,
  47. });
  48. const patternMatch = urlPattern.test(url);
  49. console.info(pattern, patternMatch);
  50. if (patternMatch) {
  51. return selectors[pattern];
  52. }
  53. }
  54. return null;
  55. }
  56.  
  57. const currentSelectors = getSelectorsForCurrentURL();
  58. if (currentSelectors) {
  59. document.addEventListener("keydown", function (event) {
  60. const selector = currentSelectors[event.key];
  61. if (selector) {
  62. event.preventDefault();
  63. const element = document.querySelector(selector);
  64. if (element) {
  65. element.click();
  66. }
  67. }
  68. });
  69. }
  70. })();