Derpibooru - Download All

Adds a download button that lets you download all images in a gallery.

目前為 2014-09-29 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Derpibooru - Download All
// @namespace   Selbi
// @include     http*://*derpiboo.ru/*
// @include     http*://*derpibooru.org/*
// @version     1.1
// @description Adds a download button that lets you download all images in a gallery.
// ==/UserScript==

const INTERVAL_TIME = 1000;
const URL_NAME = location.protocol + "//" + location.hostname + location.pathname;

$(".metabar:eq(0)").append('<a href="javascript:void()" id="GetAllLinks">Get All Links</a> <a href="javascript:void()" id="StartDownload" style="display:none">Start Download!</a>');

var pagecount = (/\d+/).exec($(".last a").attr("href"));
if (pagecount == null) pagecount = 1;
var linksarr = [];
var i = 0;

$("#GetAllLinks").click(function(){
	$(this).attr('style', 'pointer-events:none; cursor:default;').html("Grabbings Links... (0)");
	for (var int=1; int<=pagecount; int++){
		$.ajax({
			async: false,
			type: 'GET',
			url: URL_NAME + "?page=" + int,
			success: function(data){
				$(".image_container", data).each(function(){
					linksarr.push($(this).attr("data-download-uri"));					
					$("#GetAllLinks").html("Grabbings Links... (" + linksarr.length + ")");
				});
			}
		});
	}
	$("#GetAllLinks").hide();
	$("#StartDownload").html("Start Download! (0/" + linksarr.length + ") [Warning: Opens a new tab for each image!]").show();
});

function downloadImage(){
	window.open(linksarr[i], '_blank');
	// GM_openInTab(linksarr[i]);

	$("#StartDownload").html("Downloading... (" + (i+1) + "/" + linksarr.length + ")");
	i++;
	if (i < (linksarr.length)) {
		setTimeout(function(){downloadImage()}, INTERVAL_TIME);
	} else {
		$("#StartDownload").attr('style', 'pointer-events:none; cursor:default;').html("Finished Download! (" + i + "/" + linksarr.length + ")");
	}
}

$("#StartDownload").click(function(){
	$(this).html("Downloading... (0/" + linksarr.length + ")");
	setTimeout(function(){downloadImage()}, INTERVAL_TIME);
	var timer = setInterval();
});