Arrow Key Pager

Press E for next page, Q for previous page

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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(); }
  });

})();