LargeBooru

Increases the thumbnail size for Danbooru

От 27.02.2017. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

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

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name          LargeBooru
// @namespace     largebooru
// @version       1.20
// @description   Increases the thumbnail size for Danbooru
// @run-at        document-end
// @include       http://*.donmai.us/*
// @include       https://*.donmai.us/*
// @exclude       http://*.donmai.us/data/*
// @exclude       https://*.donmai.us/data/*
// ==/UserScript==

//----User defined variables----
var dimensions = 300;
var gap = 10;
var loadGIFs = true;
var loadVideos = true;
var loadOriginals = false; //Not recommended, will take a LONG time to load.
//------------------------------

var gifValue = "-large-"; if (!loadGIFs) gifValue = "-preview-";
var videosValue = "-large-"; if (!loadVideos) videosValue = "-preview-";
var origValue = "-large-"; if (loadOriginals) {origValue="-";gifValue="-";videosValue="-";};

var exts = ["jpeg","jpg","png","gif","mp4","webm","zip","swf","1","avi","bmp","html","mp3","mpg","pdf","rar","wmv"];
//The ones after swf are just to prevent the script from crashing. You'll never encounter them unless you go out of your way to.
var toGrab = [origValue,origValue,origValue,gifValue,videosValue,videosValue,videosValue,"-preview-","-preview-","-preview-","-preview-","-preview-","-preview-","-preview-","-preview-","-preview-","-preview-"];

var db = dimensions + gap + "px !important; ";
var d = dimensions + "px";
var posts = document.getElementsByClassName("post-preview");
var imgs = document.querySelectorAll("[itemprop='thumbnailUrl']");
var newElems = [];
var queue = [];
var endpoint = posts.length;
var counter = 0;
var clamp = 0;

$(document).ready (function() {
    for (var x = 0; x < posts.length; x++) {
        var Data = posts[x];
        var Image = imgs[x];
        var ext = Data.getAttribute("data-file-ext");
        var width = Data.getAttribute("data-width");
        var height = Data.getAttribute("data-height");
        var denom = Math.max(width, height) / dimensions;
        var newwidth = Math.round(width / denom);
        var newheight = Math.round(height / denom);
        Image.style.width = newwidth + "px";
        Image.style.height = newheight + "px";
        Image.style.maxHeight = d;
        Image.style.maxWidth = d;
        Data.setAttribute("style", Data.getAttribute("style") + "; margin: 0 !imporant; ");
        Data.setAttribute("style", Data.getAttribute("style") + "height: " + db);
        Data.setAttribute("style", Data.getAttribute("style") + "width: " + db);
        Data.setAttribute("style", Data.getAttribute("style") + "line-height: " + db);
        if (ext != "webm" && ext != "mp4" && ext != "zip") {
            var NewImage = document.createElement("img");
            NewImage.setAttribute("height",height);
            NewImage.setAttribute("width",width);
            NewImage.setAttribute("title",Image.getAttribute("title"));
            NewImage.style.height = newheight + "px";
            NewImage.style.width = newwidth + "px";
            NewImage.style.maxHeight = d;
            NewImage.style.maxWidth = d;
            NewImage.style.position = "absolute";
            Image.parentNode.insertBefore(NewImage, Image);
            newElems.push(NewImage);
        } else {
            var Video = document.createElement("video");    
            Video.setAttribute("autoplay","autoplay");
            Video.setAttribute("loop","loop");
            Video.volume = 0.0;
            Video.setAttribute("height",height);
            Video.setAttribute("width",width);
            Video.setAttribute("title",Image.getAttribute("title"));
            Video.style.height = newheight + "px";
            Video.style.width = newwidth + "px";
            Video.style.maxHeight = d;
            Video.style.maxWidth = d;
            Video.style.position = "absolute";
            Video.style.marginTop = "2px"; //Don't know why this is necessary
            Video.style.marginLeft = "2px";
            Image.parentNode.insertBefore(Video, Image);
            newElems.push(Video);
        }
    }
    Array.prototype.forEach.call(imgs, function(img) {img.addEventListener("load", queueit(img), false);});
});

function iscached(img_url){
    var imgEle = document.createElement("img");
    imgEle.src = img_url;
    var answer = imgEle.complete || (imgEle.width+imgEle.height) > 0
    imgEle.removeAttribute("src")
    return answer;
}

function queueit(img) {
    var imgindex = Array.prototype.indexOf.call(imgs, img);
    if (!iscached(posts[imgindex].getAttribute("data" + toGrab[exts.indexOf(posts[imgindex].getAttribute("data-file-ext"))] + "file-url"))) {
        queue.push(imgindex);
    } else {
        clamp++;
        counter++;
        timeforbig(imgindex);
    }
}

var interval = setInterval(a, 25);
function a() {
    if (queue.length > 0 && clamp < 8) {
        var index = queue[0];
        clamp++;
        counter++;
        timeforbig(index);
        queue.splice(0, 1);
    };
    if (counter >= endpoint) clearInterval(interval);
}

function reverseClamp() {
    clamp--;
}

function timeforbig(x) {
    var Data = posts[x];
    var Elem = newElems[x];
    Elem.setAttribute("src",Data.getAttribute("data" + toGrab[exts.indexOf(Data.getAttribute("data-file-ext"))] + "file-url"));
    Elem.addEventListener("load", reverseClamp, false);
}