EX Better Thumbnails

Provides infinite scroll and larger thumbnails for gallery browsing.

Version vom 11.01.2016. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         EX Better Thumbnails
// @description      Provides infinite scroll and larger thumbnails for gallery browsing. 
// @version      0.5
// @match        http://exhentai.org/g/*
// @grant        none
// @namespace https://greasyfork.org/users/13871
// ==/UserScript==

var thisURL = document.createElement("a");
thisURL.href = document.URL;
var i = 0;
var URLGen = new URLGenerator();
var fileCount;
var len = 0;
var gdata;
const jQueryCDN = "https://code.jquery.com/jquery-1.11.3.min.js";
const JSZipCDN = "https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.js";
const api = "http://exhentai.org/api.php";

const CSSCode = ".select {float: left}";

function loadJS(URL, callback) {
    var js = document.createElement("script");
    js.type = "text/javascript";
    js.src = URL;
    if (callback) {
        js.onload = callback;
    }
    document.head.appendChild(js);
}

(function() {
    callback = function() {
        loadJS(JSZipCDN);
        changeLayout();
        injectCSS();
        // injectBar();
        request(gid, token);
        main();
    }
    loadJS(jQueryCDN, callback);
})();

function injectCSS() {
    var css = $("<style></style>");
    css.html(CSSCode);
    $("body").append(css);
}

function injectBar() {
    $('<div id="controlbar"></div>').prependTo($("#gdt"));
    var button = $('<button id="debug">debug</button>').click(function() {listChecked();});
    $('#controlbar').append(button);
}

function request(gid, token) {
    var data = {
        method: "gdata",
        gidlist: [
            [gid, token]
        ]
    };
    data = JSON.stringify(data);
    var r = $.ajax({
        url: api,
        data: data,
        dataType: "JSON",
        type: "POST",
        contentType: "application/json",
        success: function(res, error) {
            gdata = res;
            fileCount = Number(gdata["gmetadata"][0]["filecount"]);
            console.log("File count: " + fileCount);
        }
    });
}

function* URLGenerator() {
    var base = thisURL.protocol + "//" + thisURL.hostname + thisURL.pathname + "?inline_set=ts_l";
    while (true) {
        yield base + "&" + "p=" + i;
        i += 1;
    }
}

function openPageURL(URL, elem) {
    var callback = function(data) {
        var DOM = $.parseHTML(data);
        var imgURL = $(DOM).find("#img").prop("src");
        var original = ""
        try {
            original = $(DOM).find("#i7").find("a").prop("href");
        } catch (err) {
            console.log(err);
        }
        if (original) {
            imgURL = original;
        }
        if (elem) {
            elem.prop("href", imgURL);
            elem.prop("download", true);
            elem.prop("clicked", true);
            elem.css("color", "#66ff33");
        }
    }
    $.get(URL, callback);
}

function listChecked() {
    var elems = $(".select");
    var result = [];
    for (var i = 0; i < elems.length; i++) {
        if (elems[i].checked) {
            result.push(elems[i].parentNode.parentNode);
        }
    }
    return result;
}

function insert(URL) {
    $.get(URL, function(data) {
        var DOM = $.parseHTML(data);
        $(DOM).find(".gdtl").each(function() {
            var title = $(this).find("img").prop("title");
            var fname = title.match(/[\d\w]+.\w+$/);
            var caption = $('<div class="caption"></div>');
            $(caption).appendTo(this);
            var pageURL = $(this).find("a").prop("href");
            $(caption).html("<a href=" + '"javascript: void(0);"' +">"+ fname + "</a>");
            // var checkBox = $('<input class="select" name="' + fname + '" type="checkbox">');
            $(caption).find("a").click(function() {
                openPageURL(pageURL, $(caption).find("a"));
            });
            // $(this).find("img").after(checkBox);
            $("#gdt > .c").before(this);
            $(this).hide().fadeIn();
        });
    })
}

function call() {
    var url = URLGen.next().value;
    console.log(url);
    insert(url);
}

function changeLayout() {
    $("#asm, #gdo, .gtb, #frontpage").remove();
    var thumbnails = document.getElementById("gdt");
    document.body.insertBefore(thumbnails, document.body.lastChild);
    $(".gdtm, .gdtl").each(function() {
        $(this).remove()
    })
}

function main() {
    if (len == 0) {
        call();
    }
    $(window).scroll(function() {
        len = $(".gdtl").length;
        if (len < fileCount && $(window).scrollTop() + $(window).height() ==  $(document).height()) {
            call();
        }
    })
}