Gelbooru "Index" Button

Adds an "Index" button on post pages, allowing you to return to a search starting from the ID of the current post you're on

2025-02-02 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Gelbooru "Index" Button
// @namespace    https://gelbooru.com/
// @version      1.0
// @description  Adds an "Index" button on post pages, allowing you to return to a search starting from the ID of the current post you're on
// @match        https://gelbooru.com/index.php?page=post&s=view*
// @icon         https://gelbooru.com/favicon.ico
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    if (location.hostname !== 'gelbooru.com') return;

    const url = new URL(window.location.href);
    const urlParams = url.searchParams;

    const currentId = urlParams.get('id');
    if (!currentId) return; // If no post ID, do nothing

    urlParams.delete('id');
    urlParams.set('s', 'list');

    const rawTags = urlParams.get('tags') || '';
    let decodedTags = decodeURIComponent(rawTags);

    const newIdSearch = 'id:=<' + currentId;

    const idSearchRegex = /id:=<\d+/i;
    if (idSearchRegex.test(decodedTags)) {
        decodedTags = decodedTags.replace(idSearchRegex, newIdSearch);
    } else {
        decodedTags = decodedTags.trim();
        if (decodedTags) decodedTags += ' ';
        decodedTags += newIdSearch;
    }

    urlParams.set('tags', decodedTags.trim());

    const finalUrl = `${url.origin}${url.pathname}?${urlParams.toString()}`;

    const box = document.createElement('div');
    box.className = 'alert alert-info';
    box.style.textAlign = 'center';
    box.style.margin = '10px 0px';
    box.style.padding = '10px';

    const indexLink = document.createElement('a');
    indexLink.textContent = 'Index';
    indexLink.href = finalUrl;

    box.appendChild(indexLink);

    const navContainers = document.querySelectorAll('.alert.alert-info');
    if (navContainers.length > 0) {
        navContainers[navContainers.length - 1].insertAdjacentElement('afterend', box);
    } else {
        const mainBody = document.querySelector('.mainBodyPadding');
        if (mainBody) mainBody.appendChild(box);
    }
})();