AO3: Use Left/Right Arrow-Keys to Navigate

use the left/right arrow keys to jump between pages, chapters, works in a series

目前为 2023-11-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name AO3: Use Left/Right Arrow-Keys to Navigate
  3. // @namespace https://greasyfork.org/en/users/906106-escctrl
  4. // @version 1.0
  5. // @description use the left/right arrow keys to jump between pages, chapters, works in a series
  6. // @author escctrl
  7. // @match https://*.archiveofourown.org/*
  8. // @grant none
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function($) {
  14. 'use strict';
  15.  
  16. // this uses the first of whichever is encountered:
  17. // (A) the "jump to page" links at the top of lists, like on works/bookmarks listings, tag search results, etc
  18. // (B) then the chapters in a work
  19. // (C) and finally the works in a series
  20. // meaning that if you're on chapter 1 of work #3 in a series, pressing the left-arrow key will take you to work #2 in the series
  21. // if a work is in multiple series, it's not quite reliable because it will use the first one that shows up in the metadata
  22. let page_prev = $('.pagination .previous a, .work.navigation .chapter.previous a, .work.meta .series a.previous');
  23. let page_next = $('.pagination .next a, .work.navigation .chapter.next a, .work.meta .series a.next');
  24.  
  25. $(document).keydown(function(event){
  26. var key = event.which;
  27. switch(key) {
  28. case 37: // Key left.
  29. if (page_prev.length > 0) window.location.assign(page_prev[0].href);
  30. break;
  31. case 39: // Key right.
  32. if (page_next.length > 0) window.location.assign(page_next[0].href);
  33. break;
  34. default:
  35. break;
  36. }
  37. });
  38.  
  39. })(jQuery);