Javdb 键盘翻页

对 Javdb 的内容使用左右方向键来翻页

Tính đến 21-08-2025. Xem phiên bản mới nhất.

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

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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         Javdb 键盘翻页
// @description  对 Javdb 的内容使用左右方向键来翻页
// @namespace    zerobiubiu.top
// @author       zerobiubiu
// @version      1.0
// @match        https://javdb.com/*
// @exclude      https://javdb.com/v/*
// @license      MIT
// @icon         https://javdb.com/favicon-32x32.png
// ==/UserScript==

(function () {
    'use strict';

    // ✏️ 根据页面实际情况修改这两行选择器:
    const SELECTOR_LEFT = "body > section > div > nav > a.pagination-previous";
    const SELECTOR_RIGHT = "body > section > div > nav > a.pagination-next";

    // 当焦点在输入框/编辑器时不拦截方向键
    function isTyping() {
        const el = document.activeElement;
        if (!el) return false;
        const tag = el.tagName;
        const editable = el.isContentEditable;
        return editable ||
            tag === 'INPUT' ||
            tag === 'TEXTAREA' ||
            tag === 'SELECT';
    }

    function safeClick(a) {
        if (!a) return false;
        // 优先用原生 click
        if (typeof a.click === 'function') {
            a.click();
            return true;
        }
        // 兜底派发 MouseEvent(注意 isTrusted 无法伪造)
        const evt = new MouseEvent('click', { bubbles: true, cancelable: true });
        return a.dispatchEvent(evt);
    }

    // 避免长按方向键连发:需要按下再抬起才接受下一次
    let lockLeft = false;
    let lockRight = false;

    window.addEventListener('keydown', (e) => {
        if (isTyping()) return;
        if (e.key === 'ArrowLeft' && !lockLeft) {
            const a = document.querySelector(SELECTOR_LEFT) || null;
            if (a) {
                e.preventDefault();
                safeClick(a);
                lockLeft = true;
            }
        } else if (e.key === 'ArrowRight' && !lockRight) {
            const a = document.querySelector(SELECTOR_RIGHT) || null;
            if (a) {
                e.preventDefault();
                safeClick(a);
                lockRight = true;
            }
        }
    }, { passive: false });

    window.addEventListener('keyup', (e) => {
        if (e.key === 'ArrowLeft') lockLeft = false;
        if (e.key === 'ArrowRight') lockRight = false;
    });
})();