Add Keyboard Shortcut for Generic Next/Previous Page

Add CTRL+ArrowLeft and CTRL+ArrowRight for generic next/previous page. It will click the last found link whose text starts/ends with e.g. "Next", "Prev", or "Previous".

当前为 2019-01-15 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Add Keyboard Shortcut for Generic Next/Previous Page
  3. // @namespace AddKeyboardShortcutForGenericNextPreviousPage
  4. // @version 1.0.4
  5. // @license GNU AGPLv3
  6. // @description Add CTRL+ArrowLeft and CTRL+ArrowRight for generic next/previous page. It will click the last found link whose text starts/ends with e.g. "Next", "Prev", or "Previous".
  7. // @author jcunews
  8. // @include *://*/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function(rxPrev, rxNext) {
  13. rxPrevious = /^prev(ious)?\b|\bprev(ious)?$/i;
  14. rxNext = /^next\b|\bnext$/i;
  15.  
  16. addEventListener("keydown", function(ev) {
  17.  
  18. function clickLink(rx, i, r) {
  19. for (i = document.links.length-1; i >= 0; i--) {
  20. if (rx.test(document.links[i].textContent.trim()) || rx.test(document.links[i].getAttribute("rel"))) {
  21. ev.preventDefault();
  22. document.links[i].click();
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28.  
  29. if (ev.ctrlKey && !ev.altKey && !ev.shiftKey) {
  30. if (document.activeElement && (
  31. (/^(INPUT|TEXTAREA)$/).test(document.activeElement.tagName) ||
  32. document.activeElement.isContentEditable)) return;
  33. switch (ev.key) {
  34. case "ArrowLeft": //previous
  35. if (clickLink(rxPrevious)) return;
  36. break;
  37. case "ArrowRight": //next
  38. if (clickLink(rxNext)) return;
  39. break;
  40. }
  41. }
  42. });
  43. })();

QingJ © 2025

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