booru keybinds

Adds galllery page navigation keybinds to various booru sites

2025/12/11のページです。最新版はこちら

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name            booru keybinds
// @namespace       861ddd094884eac5bea7a3b12e074f34
// @version         2.1
// @description     Adds galllery page navigation keybinds to various booru sites
// @author          Anonymous
// @match           https://rule34.xxx/index.php?page=post&s=list&*
// @include         /^https:\/\/yande\.re\/post(\?page=[1-9]+)?([&?]tags=[^&]+)?/
// @include         /^https:\/\/rule34\.us\/index\.php\?r=posts(%2F|\/)index.*/
// @match           https://gelbooru.com/index.php?page=post&s=list&*
// @grant           none
// @license         MIT-0
// ==/UserScript==

(function() {
    'use strict';

    const PAGE_DOMAINS = ['yande.re', 'rule34.us'];
    const PID_DOMAINS = {'rule34.xxx': 42, 'gelbooru.com': 42};

    const PARAMS = new URLSearchParams(window.location.search);
    const DOMAIN = window.location.hostname;

    function detectPaginationType() {
        if (PARAMS.has('s') || DOMAIN in PID_DOMAINS) {
            return 'pid';
        } else if (PARAMS.has('page') || PAGE_DOMAINS.indexOf(DOMAIN) > -1) {
            return 'page';
        }
        return null;
    }

    function getCurrentPage() {
        const type = detectPaginationType();
        if (type === 'pid') {
            return parseInt(PARAMS.get('pid')) || 0;
        } else if (type === 'page') {
            return parseInt(PARAMS.get('page')) || 1;
        }
        return null;
    }

    function calculatePreviousPage(type, current, pageLength) {
        if (type === 'pid') {
            if (current > 0) {
                return Math.max(0, current - pageLength);
            }
        } else if (type === 'page') {
            if (current > 1) {
                return (current - 1);
            }
        }
        return null;
    }

    function calculateNextPage(type, current, pageLength) {
        if (type === 'pid') {
            return (current + pageLength);
        } else if (type === 'page') {
            return (current + 1);
        }
        return null;
    }

    function navigate(direction) {
        const type = detectPaginationType();
        const current = getCurrentPage();

        let pageLength;null
        if (type == 'pid') {
            pageLength = PID_DOMAINS[DOMAIN];
        } else if (type == 'page') {
            pageLength = PAGE_DOMAINS[DOMAIN];
        }

        let dest;
        if (direction == 'previous') {
            dest = calculatePreviousPage(type, current, pageLength);
        } else if (direction = 'next') {
            dest = calculateNextPage(type, current, pageLength);
        }
        if (dest == null) return false;

        if (type === 'pid') {
            PARAMS.set('pid', dest);
        } else if (type === 'page') {
            PARAMS.set('page', dest);
        } else {
            console.log('Keybind caught. Navigation failed!');
            console.debug(`direction=${direction}, type=${type}, current=${current}, pageLength=${pageLength}`);
            return false;
        }

        window.location.href = `${window.location.pathname}?${PARAMS.toString()}`;
    }

    // Only activate if pagination is detected
    const paginationType = detectPaginationType();
    if (!paginationType) {
        return false;
    }

    // Add keyboard event listener
    document.addEventListener('keydown', function(e) {
        // Ignore if user is typing in an input field
        if (
            e.target.tagName === 'INPUT'
            || e.target.tagName === 'TEXTAREA'
        ) return;

        switch(e.key) {
            case 'ArrowLeft':
                e.preventDefault();
                navigate('previous');
                break;
            case 'ArrowRight':
                e.preventDefault();
                navigate('next');
                break;
        }
    });

    console.log(`Keybinds loaded (${paginationType} mode). Use ← → arrow keys to navigate gallery pages.`);
})();