AO3: Use Left/Right Arrow-Keys to Navigate

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

Ajankohdalta 4.11.2023. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         AO3: Use Left/Right Arrow-Keys to Navigate
// @namespace    https://greasyfork.org/en/users/906106-escctrl
// @version      1.0
// @description  use the left/right arrow keys to jump between pages, chapters, works in a series
// @author       escctrl
// @match        https://*.archiveofourown.org/*
// @grant        none
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js
// @license      MIT
// ==/UserScript==

(function($) {
    'use strict';

    // this uses the first of whichever is encountered:
    // (A) the "jump to page" links at the top of lists, like on works/bookmarks listings, tag search results, etc
    // (B) then the chapters in a work
    // (C) and finally the works in a series
    // 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
    // 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
    let page_prev = $('.pagination .previous a, .work.navigation .chapter.previous a, .work.meta .series a.previous');
    let page_next = $('.pagination .next a, .work.navigation .chapter.next a, .work.meta .series a.next');

    $(document).keydown(function(event){
        var key = event.which;
        switch(key) {
            case 37: // Key left.
                if (page_prev.length > 0) window.location.assign(page_prev[0].href);
                break;
            case 39: // Key right.
                if (page_next.length > 0) window.location.assign(page_next[0].href);
                break;
            default:
                break;
        }
    });

})(jQuery);