Gelbooru Search Helper

Adds Score, General, Solo and 1girl buttons to Gelbooru search and keeps them in place.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Advertisement:

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

Advertisement:

// ==UserScript==
// @name         Gelbooru Search Helper
// @namespace    http://tampermonkey.net/
// @version      3.1.1
// @description  Adds Score, General, Solo and 1girl buttons to Gelbooru search and keeps them in place.
// @author       RuriDragon
// @match        https://gelbooru.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gelbooru.com
// @license      MIT
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    function addSearchModifierButton(text, modifier, color) {
        const button = document.createElement('a');
        button.textContent = text;
        button.href = '#';
        button.dataset.active = 'false';
        button.style.cssText = `
            display: inline-block;
            margin: 0 5px;
            padding: 7px 15px;
            cursor: pointer;
            text-decoration: none;
            background: linear-gradient(145deg, ${color}, #333);
            color: #ffffff !important;
            border: 1px solid rgba(255, 255, 255, 0.3);
            border-radius: 8px;
            font-weight: bold;
            font-family: Arial, sans-serif;
            font-size: 13px;
            transition: all 0.3s ease;
            box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.2), inset 0px -3px 6px rgba(0, 0, 0, 0.1);
            text-align: center;
            line-height: normal;
        `;

        const checkmarkSpan = document.createElement('span');
        checkmarkSpan.innerHTML = '✓';
        checkmarkSpan.style.cssText = `
            display: none;
            margin-left: 5px;
            font-size: 14px;
        `;
        button.appendChild(checkmarkSpan);

        button.addEventListener('mouseover', function() {
            this.style.transform = 'translateY(-2px)';
            this.style.boxShadow = '0px 6px 8px rgba(0, 0, 0, 0.3), inset 0px -4px 8px rgba(0, 0, 0, 0.2)';
        });

        button.addEventListener('mouseout', function() {
            if (this.dataset.active !== 'true') {
                this.style.transform = 'translateY(0)';
                this.style.boxShadow = '0px 4px 6px rgba(0, 0, 0, 0.2), inset 0px -3px 6px rgba(0, 0, 0, 0.1)';
            }
        });

        button.onclick = function(e) {
            e.preventDefault();
            const searchInput = document.querySelector('#tags-search');
            if (!searchInput) return;

            let currentTags = searchInput.value.trim();
            let tags = currentTags.split(/\s+/).filter(tag => tag);

            if (tags.includes(modifier)) {
                tags = tags.filter(tag => tag !== modifier);
                this.dataset.active = 'false';
                checkmarkSpan.style.display = 'none';
                this.style.background = `linear-gradient(145deg, ${color}, #333)`;
            } else {
                tags.push(modifier);
                this.dataset.active = 'true';
                checkmarkSpan.style.display = 'inline';
                this.style.background = 'linear-gradient(145deg, #28a745, #1c7430)';
            }

            searchInput.value = tags.join(' ').trim();
        };

        return button;
    }

    function insertButtons() {
        const searchInput = document.querySelector('#tags-search');
        const searchButton = document.querySelector('input[name="commit"][type="submit"][value="Search"]');
        if (!searchInput || !searchButton) {
            setTimeout(insertButtons, 100);
            return;
        }

        const soloButton = addSearchModifierButton('Solo', 'solo', '#ff7b7b');
        const oneGirlButton = addSearchModifierButton('1Girl', '1girl', '#7bafff');
        const scoreButton = addSearchModifierButton('Score', 'sort:score', '#ffaf7b');
        const generalButton = addSearchModifierButton('General', 'rating:general', '#7bff7b');

        const buttonContainer = document.createElement('div');

        buttonContainer.appendChild(soloButton);
        buttonContainer.appendChild(oneGirlButton);
        buttonContainer.appendChild(scoreButton);
        buttonContainer.appendChild(generalButton);

        const isMainPage = document.querySelector('#static-index') !== null;

        if (isMainPage) {
            buttonContainer.style.display = 'flex';
            buttonContainer.style.justifyContent = 'center';
            buttonContainer.style.marginTop = '15px';
            buttonContainer.style.marginBottom = '20px';

            const formElement = searchInput.closest('form');
            formElement.insertAdjacentElement('afterend', buttonContainer);
        } else {
            buttonContainer.style.position = 'absolute';
            buttonContainer.style.zIndex = '1000';

            document.body.appendChild(buttonContainer);

            const searchInputRect = searchInput.getBoundingClientRect();
            buttonContainer.style.top = `${searchInputRect.top + window.scrollY}px`;
            buttonContainer.style.right = `${document.documentElement.clientWidth - searchInputRect.right + 10}px`;
        }

        const currentTags = searchInput.value.trim().split(/\s+/);
        [
            { button: soloButton, tag: 'solo' },
            { button: oneGirlButton, tag: '1girl' },
            { button: scoreButton, tag: 'sort:score' },
            { button: generalButton, tag: 'rating:general' }
        ].forEach(({ button, tag }) => {
            if (currentTags.includes(tag)) {
                button.dataset.active = 'true';
                button.querySelector('span').style.display = 'inline';
                button.style.background = 'linear-gradient(145deg, #28a745, #1c7430)';
            }
        });
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', insertButtons);
    } else {
        insertButtons();
    }
})();