e621 Page Result Grabber

Adds buttons below the tag searchbar to copy queries for the page result post ID's to the clipboard.

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!)

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!)

// ==UserScript==
// @name         e621 Page Result Grabber
// @namespace    https://greasyfork.org/users/1582013
// @version      1.0
// @description  Adds buttons below the tag searchbar to copy queries for the page result post ID's to the clipboard.
// @author       FreekyCreep
// @license      GNU GPLv3
// @match        https://e621.net/posts?*
// @match        https://e926.net/posts?*
// @grant        GM_addStyle
// ==/UserScript==
(function () {
    //site elements
    const TAGS = document.getElementById("tags");
    const SEARCH_CONTROLS = document.querySelector(".search-controls");
    const THUMBNAILS = document.querySelectorAll(".posts-container > .thumbnail");

    //queries
    const tagLimit = 40;
    const queryCount = Math.ceil(THUMBNAILS.length / tagLimit);
    const queries = new Array(queryCount).fill("");

    //functions
    function buttonClickHandler(e) {
        let button = e.target;
        let queryIndex = Number(button.dataset.index);
        button.disabled = true;
        if (!queries[queryIndex]) {
            const start = queryIndex * tagLimit;
            const end = (queryIndex === queryCount) ? THUMBNAILS.length : start + tagLimit;
            for (let i = start; i < end; i++) queries[queryIndex] += "~id:" + THUMBNAILS[i].dataset.id + " ";
        }
        navigator.clipboard.writeText(queries[queryIndex]).then(() => button.classList.add("active")).catch(err => console.error("Failed to copy query:", err));
        setTimeout(() => {
            button.classList.remove("active");
            button.disabled = false;
        }, 500);
    }
    function thumbnailClickHandler(e) {
        if (!e.ctrlKey || !e.shiftKey || e.button || e.target === e.currentTarget || e.target.tagName === "HR") return;
        e.preventDefault();
        let target = e.target;
        while (target.parentNode !== e.currentTarget) target = target.parentNode;
        TAGS.value += " -id:" + target.dataset.id;
        const scrollY = window.scrollY;
        TAGS.style.height = 0;
        TAGS.style.height = TAGS.scrollHeight + "px";
        window.scrollBy(0, scrollY - window.scrollY);
    }

    //DOM+events
    const buttonText = (queryCount < 5) ? ",'{:') " : "";
    for (let i = 0; i < queryCount; i++) {
        let button = document.createElement("button");
        button.className = "st-button freeky-button";
        button.textContent = buttonText + (i + 1);
        button.title = "Copy query " + (i + 1);
        button.dataset.index = i;
        button.addEventListener("click", buttonClickHandler);
        SEARCH_CONTROLS.appendChild(button);
    }
    for (let i = tagLimit; i < THUMBNAILS.length; i += tagLimit) THUMBNAILS[i].before(document.createElement("hr"));
    document.querySelector(".posts-container").addEventListener("click", thumbnailClickHandler);

    //styles
    GM_addStyle(`
        .freeky-button {
            min-width: 34px;
            align-items: center;
            font-size: 13.6px;
            letter-spacing: -1px;
        }
        .posts-container > hr {
            grid-column: 1 / -1;
            margin: 15px;
            border-style: dashed;
        }
        #mode-box {
            margin-top: 20px !important;
        }
        body[data-st-fullscreen='true'] .posts-index-stats {
            margin-right: ${43 * queryCount + 80}px !important;
        }
    `);
    if (queryCount < 5) return;
    GM_addStyle(`
        body[data-st-fullscreen='false'] .freeky-button {
            min-width: 24px !important;
        }
        body[data-st-fullscreen='false'] .search-controls {
            gap: 2px !important;
        }
    `);
})();