ThGrab

Grab contents from thothub network (private)

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        ThGrab
// @version     0.1.8
// @description Grab contents from thothub network (private)
// @author      Fredddy
// @icon        https://thothub.mx/favicon.ico
// @include     *://thothub.*/*/*
// @require     https://code.jquery.com/jquery-latest.min.js
// @require     https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/fancybox/fancybox.umd.js
// @resource    fancyboxCSS https://cdn.jsdelivr.net/npm/@fancyapps/[email protected]/dist/fancybox/fancybox.css
// @grant       GM_addStyle
// @grant       GM_getResourceText
// @license     GPLv3
// @namespace https://greasyfork.org/users/1379128
// ==/UserScript==

(() => {
    "use strict";
    GM_addStyle(GM_getResourceText("fancyboxCSS"));
    $(document).ready(function () {
        if (/^https:\/\/thothub\..*\/albums\/\d+\/.*$/.test(document.baseURI)) {
            var privateAcess;

            Fancybox.bind('[data-fancybox="gallery"]', {
                compact: false,
                contentClick: "iterateZoom",
                Images: {
                    Panzoom: {
                        maxScale: 3,
                    },
                },
                Toolbar: {
                    display: {
                        left: [
                            "infobar",
                            "download"
                        ],
                        right: [
                            "iterateZoom",
                            "close",
                        ],
                    }
                }
            });

            getAlbum();
            console.info(`[ThGrab] Enable bypass THGB`);
        }

        function getAlbum() {
            let imgs;

            if (!$(".images .message").length) {
                privateAcess = false;
                imgs = $(".images a img");
                console.info(`[ThGrab] Fetch ${imgs.length} pics from public album`);
            } else {
                privateAcess = true;
                imgs = $(".images .item.private img");
                $(".images .message").remove();
                console.info(`[ThGrab] Fetch ${imgs.length} pics from private album`);
            }

            document.title = `${document.title.split("-")[0]} • (${privateAcess ? 'Bypass' : 'Public'})`;
            $(".headline").html(`<div id="album-title" style="
                width: 50%;
                margin: 0 auto;
                text-align: center;">
                <h2>${document.title}</h2>
            </div>`);

            if (imgs.length >= 1) {
                const loadPromises = [];

                imgs.each(function (index) {
                    let img = $(this);
                    loadPromises.push(new Promise((resolve) => {
                        img.on("load", function () {
                            if (!img.attr("src").includes("sources/")) {
                                let src = img
                                    .attr("src")
                                    .replace("main/", "")
                                    .replace(/\d+x\d+\//, "sources/");
                                img.attr("src", src);
                                img.attr("title", `${document.title} - ${index + 1}`);
                                img.attr("data-fancybox", "gallery");
                                img.attr("data-caption", `${document.title} - #${index + 1}`);
                                img.css("cursor", "pointer");
                            }
                            resolve();
                        });
                    }));
                });

                Promise.all(loadPromises).then(() => {
                    if (!privateAcess) {
                        const callback = function (mutationsList, observer) {
                            mutationsList.forEach(mutation => {
                                if (mutation.type === 'childList') {
                                    mutation.addedNodes.forEach(node => {
                                        if (node.classList && node.classList.contains('fancybox-close')) {
                                            node.click();
                                            console.info(`[ThGrab] Close default UI`);
                                        }
                                    });
                                }
                            });
                        };

                        const observer = new MutationObserver(callback);

                        observer.observe(document.body, {
                            childList: true,
                            subtree: true
                        });
                    }
                });
            }
        }
    });
})();