Derpibooru - Download All

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

Tính đến 29-09-2014. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

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