Universal Keyboard Navigation

Enables Previous and Next page navigation using keyboard buttons on any site. Browse your favorite Manga, Manhwa, comic, novel sites with ease.

  1. // ==UserScript==
  2. // @name Universal Keyboard Navigation
  3. // @namespace http://tampermonkey.net/
  4. // @version 202403301
  5. // @description Enables Previous and Next page navigation using keyboard buttons on any site. Browse your favorite Manga, Manhwa, comic, novel sites with ease.
  6. // @author Chief Legend
  7. // @match *://*/*
  8. // @exclude *://*.youtube.com/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=universalnavigation.com
  10. // @license MIT
  11. // @grant none
  12. // @noframes
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // List of acceptable innerText values for previous and next pages or chapters
  19. const navigationTexts = {
  20. prev: ["Previous Chapter", "Prev Chapter", "Prev Page", "Prev"],
  21. next: ["Next Chapter", "Next Page", "Next"]
  22. };
  23.  
  24. // Cache for the last found links to improve performance
  25. let lastFoundLinks = {
  26. prev: null,
  27. next: null
  28. };
  29.  
  30. function findLink(textArray) {
  31. for (let text of textArray) {
  32. let lowerText = text.toLowerCase();
  33.  
  34. // XPath to find case-insensitive match
  35. let xpath = `//a[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'${lowerText}')]`;
  36.  
  37. let link = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  38. if (link) return link;
  39. }
  40. return null;
  41. }
  42.  
  43. // Function to simulate click on Prev or Next link
  44. function navigate(direction) {
  45. if (lastFoundLinks[direction]) {
  46. // If we have cached the link, use it
  47. lastFoundLinks[direction].click();
  48. return;
  49. }
  50.  
  51. // Find the link using the list of acceptable values
  52. let link = findLink(navigationTexts[direction]);
  53.  
  54. // Cache the link for subsequent use
  55. if (link) {
  56. lastFoundLinks[direction] = link;
  57. link.click();
  58. }
  59. }
  60.  
  61. // Add keydown event listener to the document
  62. document.addEventListener('keydown', function(event) {
  63. // Check if the left arrow key (ArrowLeft) or right arrow key (ArrowRight) was pressed
  64. if (event.key === 'ArrowLeft') {
  65. navigate('prev');
  66. } else if (event.key === 'ArrowRight') {
  67. navigate('next');
  68. }
  69. });
  70. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址