booru keybinds

Adds galllery page navigation keybinds to various booru sites

Versione datata 11/12/2025. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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