booru keybinds

Add keybinds for navigating galllery pages of select booru sites

2025-12-11 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         booru keybinds
// @namespace    861ddd094884eac5bea7a3b12e074f34
// @version      2.0
// @description  Add keybinds for navigating galllery pages of select booru sites
// @author       Anonymous
// @match        https://rule34.xxx/index.php?page=post&s=list&*
// @match        https://yande.re/post?page=*
// @grant        none
// @license      MIT-0
// ==/UserScript==

(function() {
    'use strict';

    const ITEMS_PER_PAGE = 42;

    // Detect pagination type
    function detectPaginationType() {
        const params = new URLSearchParams(window.location.search);

        if (params.has('pid')) {
            return 'pid'; // Rule34.xxx-style (pid=0, pid=42, pid=84...)
        } else if (params.has('page')) {
            return 'page'; // Standard pagination (page=1, page=2, page=3...)
        }
        return null;
    }

    function getCurrentPage() {
        const params = new URLSearchParams(window.location.search);
        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 navigateToPage(value) {
        const params = new URLSearchParams(window.location.search);
        const type = detectPaginationType();

        if (type === 'pid') {
            params.set('pid', value);
        } else if (type === 'page') {
            params.set('page', value);
        }

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

    function goToPreviousPage() {
        const type = detectPaginationType();
        const current = getCurrentPage();

        if (type === 'pid') {
            if (current > 0) {
                const previous = Math.max(0, current - ITEMS_PER_PAGE);
                navigateToPage(previous);
            }
        } else if (type === 'page') {
            if (current > 1) {
                navigateToPage(current - 1);
            }
        }
    }

    function goToNextPage() {
        const type = detectPaginationType();
        const current = getCurrentPage();

        if (type === 'pid') {
            navigateToPage(current + ITEMS_PER_PAGE);
        } else if (type === 'page') {
            navigateToPage(current + 1);
        }
    }

    // Only activate if pagination is detected
    const paginationType = detectPaginationType();

    if (!paginationType) {
        return; // No pagination detected, exit script
    }

    // 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();
                goToPreviousPage();
                break;
            case 'ArrowRight':
                e.preventDefault();
                goToNextPage();
                break;
        }
    });

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