Arrow Key Pager

Press E for next page, Q for previous page

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

Advertisement:

// ==UserScript==
// @name         Arrow Key Pager
// @namespace    http://tampermonkey.net/
// @version      2.2
// @description  Press E for next page, Q for previous page
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {

  function findLink(dir) {
    // Bilibili
    const bTxt = dir === 'next' ? '下一页' : '上一页';
    const bBtn = Array.from(document.querySelectorAll('button.vui_pagenation--btn-side')).find(b => b.textContent.trim() === bTxt);
    if (bBtn) return bBtn;

    // Google
    if (dir === 'next') {
      const el = document.querySelector('#pnnext, a[aria-label="Next page"]');
      if (el) return el;
      const links = document.querySelectorAll('a[href*="start="]');
      if (links.length) return links[links.length - 1];
    } else {
      const el = document.querySelector('#pnprev, a[aria-label="Previous page"]');
      if (el) return el;
    }

    // rule34video
    const svg = document.querySelector(`svg.custom-${dir === 'next' ? 'right' : 'left'}`);
    if (svg) return svg.closest('a');

    return null;
  }

  document.addEventListener('keydown', (e) => {
    const tag = document.activeElement?.tagName;
    if (['INPUT', 'TEXTAREA', 'SELECT'].includes(tag) || document.activeElement?.isContentEditable) return;
    if (!['KeyE', 'KeyQ'].includes(e.code)) return;

    const el = findLink(e.code === 'KeyE' ? 'next' : 'prev');
    if (el) { e.preventDefault(); el.click(); }
  });

})();