Arrow Keys Flip Pages

Trigger Pages Flips with custom arrow key shortcuts

  1. // ==UserScript==
  2. // @name Arrow Keys Flip Pages
  3. // @namespace https://4kliksAlex.github.com/
  4. // @version v0.2.4
  5. // @description Trigger Pages Flips with custom arrow key shortcuts
  6. // @author 4kliksAlex
  7. // @match *://*/*
  8. // @icon https://upload.wikimedia.org/wikipedia/commons/c/c7/Computer_keyboard_German-key-4.svg
  9. // @grant none
  10. // @license GPLv3
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. "use strict";
  15.  
  16. const selectors = {
  17. "*://*.oracle.com/javase/tutorial/*": {
  18. ArrowLeft: "body > div.MainFlow_wide > div:nth-child(6) > a:nth-child(1)",
  19. ArrowRight: "body > div.MainFlow_wide > div:nth-child(6) > a:nth-child(3)"
  20. },
  21. // "*://*.google.com/search?*": {
  22. // ArrowLeft: "#pnprev",
  23. // ArrowRight: "#pnnext",
  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. })();