Javdb 键盘翻页

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

21.08.2025 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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;
    });
})();