LargeBooru

Increases the thumbnail size for Danbooru

目前為 2017-02-27 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
}