EX Better Thumbnails

Provides infinite scroll and larger thumbnails for gallery browsing.

Per 11-01-2016. Zie de nieuwste versie.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey, Greasemonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Violentmonkey.

Voor het installeren van scripts heb je een extensie nodig, zoals Tampermonkey of Userscripts.

Voor het installeren van scripts heb je een extensie nodig, zoals {tampermonkey_link:Tampermonkey}.

Voor het installeren van scripts heb je een gebruikersscriptbeheerder nodig.

(Ik heb al een user script manager, laat me het downloaden!)

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een extensie nodig, zoals {stylus_link:Stylus}.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

Voor het installeren van gebruikersstijlen heb je een gebruikersstijlbeheerder nodig.

(Ik heb al een beheerder - laat me doorgaan met de installatie!)

// ==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();
        }
    })
}