booru keybinds

Adds galllery page navigation keybinds to various booru sites

Από την 11/12/2025. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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