Skip to content

Instantly share code, notes, and snippets.

@dvingerh
Created March 30, 2018 18:43
Show Gist options
  • Select an option

  • Save dvingerh/761feb64e3566de61703604bd758088c to your computer and use it in GitHub Desktop.

Select an option

Save dvingerh/761feb64e3566de61703604bd758088c to your computer and use it in GitHub Desktop.
PicturePub PixHost Batch Downloader
// ==UserScript==
// @name PicturePub Batch Downloader
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add download links and a batch download button for PixHost on Picturepub. Useful if the photos aren't added to an album.
// @author You
// @require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// @match *.pixhost.to/images/*
// @include *picturepub.net/index.php?threads*
// @grant none
// @run-at document-idle
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
$(function() {
var iteration = 1;
var url_arr;
var time = 1000;
if (window.location.hash && window.location.href.indexOf(".pixhost.to/images/")) {
$("body").html("<span id='status' style='color: white;'>Downloading...</span>");
url_arr = window.location.hash.split("*");
console.log(url_arr);
for (var i = 0; i < url_arr.length - 1; i++) {
$("body").append('<a id="#downloadlink" style="display:none;" href="' + url_arr[i].replace("#", "").replace("*", "") + '" download>Download</a>');
}
$("body").find("a").each(function() {
var link = $(this);
setTimeout(function(){
$(link)[0].click();
$("#status").text("Downloading " + iteration + " of " + (url_arr.length - 1) + "...");
iteration++;
}, time);
time+= 1000;
if (iteration == url_arr.length - 1) {
$("#status").text("Downloading finished.");
}
});
}
});
$("blockquote[class^='messageText']").each(function()
{
var count = 0;
var contains = false;
var width, widthHalf, dlButton;
$(this).find('a').each(function(){
$(this).find('img').each(function(a){
var src = $(this).attr('src');
if (src.indexOf("pixhost") !== -1)
{
contains = true;
//console.log(src);
//console.log(count);
src = src.replace("/thumbs/", "/images/").replace("//t", "//img");
width = $(this).width() - 25;
widthHalf = (width / 2) + 3;
dlButton = '<a target="_blank" class="dlPixHost" href="' + src + '" style="position: relative; margin-left: -' + (width + 25) + 'px; margin-right: 0px; padding-left: ' + widthHalf + 'px; padding-right:' + (widthHalf + 1) + 'px; background-color: rgba(0,0,0,0.7); font-weight: bold;" download>DL</a>';
$(this).parent().after(dlButton);
count++;
}
});
});
if (contains) {
$(this).parent().parent().parent().find("div.privateControls").after('<a style="margin-left: 5px;" href="javascript:void()" class="BatchDl OverlayTrigger item control" data-cacheoverlay="false" style=""><span></span>Batch Download PixHost (' + count + ' Pictures)</a>');
}
});
$("a[class^='BatchDl']").click( function(e) {e.preventDefault(); BatchDownload(this); return false; } );
function BatchDownload(button)
{
var counter = 0;
var url_str = "";
var iframe = '<iframe src="url" frameborder="0" scrolling="no" style="height: 15px; margin-left: 10px;" width="200" height="25" id="dl_iframe"></iframe>';
var first = "";
$($(button).parent().prev().prev().find('a.dlPixHost')).each(function(){
if(first == "") {
first = $(this).attr('href');
}
// var new_win = window.open($(this).attr('href') + "#download" ,"_blank",'PopUp'+ counter++ +'…', 'toolbar=no, location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=350,height=250,visible=none');
// new_win.resizeTo(250, 250);
// new_win.moveTo(100, 100);
url_str = url_str + $(this).attr('href') + "*";
});
$(button).after(iframe.replace("url", first + "#" + url_str));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment