LargeBooru

Increases the thumbnail size for Danbooru

当前为 2017-02-27 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴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);
}