KMImgDLer

Auto-download all pics

Versione datata 29/07/2020. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name     KMImgDLer
// @version  2.0
// @grant    GM_addStyle
// @grant    GM_download
// @include https://www.kaufmich.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @require https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js
// @namespace https://greasyfork.org/users/290665
// @description Auto-download all pics
// ==/UserScript==


$("head").append (
    '<link '
  + 'href="//ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.min.css" '
  + 'rel="stylesheet" type="text/css">'
);
addStyle();
var myVersion = GM_info.script.version;
var username = document.baseURI.replace(/.*\.com\//,'').replace(/#$/,'');

function artistname() {
    var name = $('h2.user-name').clone().children().remove().end().text();
    name = name.replace(/(^\s+|\s+$)/g,'');
    return name;
}
$(function() {
    var name = artistname();
    if (name.length) {
        $('.content:first').css('position','relative');
        var myspace = $('<div id="KMImgDLer"></div>').appendTo('.content:first');
        $('<div class="KMImgDLerLogo">powered by KMImgDLer '+myVersion+'</div>').appendTo(myspace);
        $('<a class="kmButton" href="#">Download all photos</a>').on('click', startDLALL).appendTo(myspace);
        var searchButton = $('<a class="kmButton" target="_blank">search LH</a>').appendTo(myspace);
        var searchQuery = (username.toLowerCase() == name.toLowerCase()) ? `"${name}"` : `("${username}" OR "${name}")`;
        $(searchButton).attr('href',`https://www.google.de/search?as_sitesearch=lusthaus.cc&q=${searchQuery}`);
    }
});

function startDLALL() {
    var downloadlist = [];
    $(preload_images).each(function() {
        var link = $(this).attr('src');
        if (1) {
            downloadlist.push(link);
            console.log(link);
        }
    });
    var name = artistname();
    var path = name;
    if (name.toLowerCase() != username.toLowerCase()) path += `,${username}`
    dlAll(path,downloadlist.filter( function (value, index, self) {
        return self.indexOf(value) === index;
    } ));
}

function dlAll(path,downloadlist) {

    var dialog = $('<div id="dialog"></div>').dialog({
        title: 'Download to '+path+' ...',
        modal: true,
        width: 600,
        buttons: {
            Ok: function() {
                $( this ).dialog( "close" );
            }
        }
    });

    for (let URL of downloadlist) {
        var name = URL.replace(/.*\//,'');
        var file = path.replace(/[^\w-\(\)]/g,'')+'/'+name;
        URL = URL.replace(/^\/\//,'https://');
        var line = $('<div class="RLDL" data-name="'+name+'">'+name+'</div>\n').appendTo(dialog);

        console.log([URL,file]);

        (function(url,filepath,filename,linediv) {
            var dl = GM_download({
                url: url,
                name: filepath,
                saveAs: false,
                onerror: function(){
                    $(linediv).append('<span class="download_error">ERROR: '+err.error+'<br>'+err.details+'</span>');
                },
                onload: function() {
                    $(linediv).append('<span class="download_ok">✓</span>');
                }
            });
        })(URL,file,name,line);

    }
}

function addStyle() {
    GM_addStyle(`
.download_error {
    color: white;
    background-color: #880010;
    padding: 1px 4px;
    border-radius: 2px;
    margin: 0px 4px;
}

.download_ok {
    color: white;
    background-color: #10a020;
    padding: 1px 4px;
    border-radius: 2px;
    margin: 0px 4px;
}
#KMImgDLer {
	position: absolute;
	top: 12px;
	right: 236px;
	overflow: visible;
	z-index: 10000;
    text-align:right;
}
#KMImgDLer .kmButton {
    margin-left:4px;
}
.KMImgDLerLogo {
    position: absolute;
    color: #e1025d;
    font-size: 9px;
    top: -15px;
    right:0px;
}
`);
}