GGBases | Thumbnails

Add images as thumbnails to the row items (on the end)

24.09.2024 itibariyledir. En son verisyonu görün.

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

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 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.

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

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

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.

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

// ==UserScript==
// @name            GGBases | Thumbnails
// @namespace       http://tampermonkey.net/
// @version         1.0.0
// @description     Add images as thumbnails to the row items (on the end)
// @author          extra.lewd
// @match           https://www.ggbases.com/*
// @exclude         https://www.ggbases.com/view.so*
// @icon            https://www.ggbases.com/favicon.ico
// @run-at          document-end
// @license         CC BY-NC-ND 4.0
// @license-url     https://creativecommons.org/licenses/by-nc-nd/4.0/
// @homepage        https://discord.gg/TcWrM6pXWD
// @homepageURL     https://discord.gg/TcWrM6pXWD
// @website         https://discord.gg/TcWrM6pXWD
// @source          https://discord.gg/TcWrM6pXWD
// @compatible      firefox
// @compatible      chrome
// @compatible      opera
// @compatible      safari
// @compatible      edge
// @grant           GM.getValue
// @grant           GM.setValue
// @grant           GM.registerMenuCommand
// ==/UserScript==

(function () {
    'use strict';
    const observer = new MutationObserver(boostrap);
    observer.observe(document.querySelector("body"), {
        childList: true,
        subtree: true,
    })

    async function boostrap() {
        const elements = document.querySelectorAll("a[name='title']:not(.gay)");
        const [width, height] = await Promise.all([GM.getValue("img.width", 300), GM.getValue("img.height", 300)]);
        elements.forEach(e => {
            e.classList.add("gay") // skip from adding img again
            const img = document.createElement("img")
            const src = parseSource(e.getAttribute("c"))
            if (!src) return;
            img.src = src;

            img.width = width;
            img.height = height;

            e.parentElement.parentElement.append(img)
        })
    }

    // stealed from ggbases.com
    const r1 = new RegExp("^http"), r2 = new RegExp("^//");

    // init
    boostrap();
    registerCommands();

    function parseSource(src) {
        if (!src || src === "" || src === " ") return;
        if (/^d[0-9]{6,8}$/.test(src)) {
            // @ts-expect-error optional argument
            src = gendlcover(src.substr(1, src.length));
        } else if (/^RJ[0-9]{6,8}$/.test(src)) {
            // @ts-expect-error optional argument
            src = gendlcover(src.substr(2, src.length));
        } else if (/^v[0-9]{6,8}$/.test(src)) {
            src = gendlcover(src.substr(1, src.length), 1);
        } else if (/^VJ[0-9]{6,8}$/.test(src)) {
            src = gendlcover(src.substr(2, src.length), 1);
        } else if (/^g[0-9]{6,7}$/.test(src)) {
            src = gengccover(src.substr(1, src.length));
        } else if (/^gc[0-9]{6,7}$/.test(src)) {
            src = gengccover(src.substr(2, src.length));
        } else if (!r1.test(src) && !r2.test(src)) {
            src = coverurl(src);
        }
        return src;
    }

    // stealed from ggbases.com
    function gendlcover(did, type) {
        let pre0 = null, dpre0 = null, npre = null;
        if (did.indexOf('0') == 0 && did.length == 8) npre = '0';
        did = parseInt(did);
        let rid = Math.ceil(did / 1000) * 1000;
        if (did < 10) { pre0 = "00000"; } else if (did < 100) { pre0 = "0000"; } else if (did < 1000) { pre0 = "000"; } else if (did < 10000) { pre0 = "00"; } else if (did < 100000) { pre0 = "0"; }
        if (rid < 10000) { dpre0 = "00"; } else if (rid < 100000) { dpre0 = "0"; }
        if (pre0) { did = pre0 + did; } if (dpre0) { rid = dpre0 + rid; } if (npre) { did = npre + did; rid = npre + rid; }
        let usecoverproxy = false;
        if (typeof Storage !== "undefined") {
            // @ts-expect-error developer is 🤡, using already loaded on website lib of dayjs
            usecoverproxy = localStorage.getItem("usecoverproxy" + dayjs().format("YYYY-MM-DD"));
        }
        return (usecoverproxy ? "//cover.ydgal.com/_200_cover/".replace("/_200_cover/", "") : "//img.dlsite.jp") + "/resize/images2/work/" + (!type ? "doujin/RJ" : "professional/VJ") + rid + "/" + (!type ? "RJ" : "VJ") + did + "_img_main_240x240.jpg";
    }
    // stealed from ggbases.com
    function gengccover(did) {
        return "//cover.ydgal.com/_200_cover/".replace("/_200_cover/", "/_300_cover/") + "/getchu/gc" + did + ".jpg";
        //return "//cover.ydgal.com/_200_cover/".replace("/_200_cover/", "") + "/brandnew/" + did + "/c" + did + "package_s.jpg";
    }
    // stealed from ggbases.com
    function coverurl(tid) {
        const num = tid.split("_")[0];
        const coverUrl = "//cover.ydgal.com/_200_cover/";
        if (parseInt(num) > 1360000) {
            return coverUrl + "new/" + tid;
        } else {
            return coverUrl + "old/" + tid;
        }
    }

    function registerCommands() {
        GM.registerMenuCommand("Set image width", () => {
            const value = parseInt(prompt("Input image width", "300"))
            if (!isNaN(value) && value > 0) {
                GM.setValue("img.width", value)
                alert("Success! Reload page to apply changes")
            }
        })
        GM.registerMenuCommand("Set image height", () => {
            const value = parseInt(prompt("Input image height", "300"))
            if (!isNaN(value) && value > 0) {
                GM.setValue("img.height", value)
                alert("Success! Reload page to apply changes")
            }
        })
    }
})();