☰

KMImgDLer

Auto-download all pics

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램을 먼저 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        KMImgDLer
// @version     3.6
// @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">')
    .append('<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">');

addStyle();
const myVersion = GM_info.script.version;

function artistname() {
    return $('.profile__card-display-name').text().trim();
}

// Hauptfunktion zum Einfügen der Buttons
function initUI() {
    // Wenn wir nicht auf einer Profilseite sind oder kein Name da ist, abbrechen
    const name = artistname();
    if (!name.length) return;

    const username = document.baseURI.replace(/.*\.com\/p\//, '').replace(/#$/, '');

    // 1. Logo einfügen (Prüfen ob schon da)
    if ($('.KMImgDLerLogo').length === 0) {
        $(`<div class="KMImgDLerLogo">enhanced by KMImgDLer ${myVersion}</div>`)
            .appendTo($('.nav__logo'));
    }

    // 2. Buttons Container prüfen
    const $actionContainer = $('.profile__more-actions');
    if ($actionContainer.length === 0) return; // Container noch nicht geladen

    // 3. Buttons einfügen (Prüfen ob schon da anhand einer Klasse oder ID)
    if ($('#km-custom-search-btn').length === 0) {

        const searchQuery = (username.toLowerCase() === name.toLowerCase()) ? `"${name}"` : `("${username}" OR "${name}")`;

        // Style fix für Content
        $('.content:first').css('position', 'relative');

        // Buttons erstellen
        $('<a id="km-custom-search-btn" title="search LH" class="btn btn__size-md btn__type-normal btn__theme-primary-white" target="_blank"><span class="material-icons md-18">search</span> LH</a>')
            .attr('href', `https://www.google.de/search?as_sitesearch=lusthaus.cc&q=${searchQuery}`)
            .prependTo($actionContainer);

        $('<a id="km-custom-dl-btn" title="Download all photos" class="btn btn__size-md btn__type-normal btn__theme-primary-white" href="#"><span class="material-icons md-18">collections</span>&#8203</button></a>')
            .on('click', (e) => {
                e.preventDefault(); // Verhindert Springen nach oben
                startDLALL(username);
            }).prependTo($actionContainer);

        $('<a id="km-custom-copy-btn" title="Copy ad data and text in BBCode format" class="btn btn__size-md btn__type-normal btn__theme-primary-white" href="#"><span class="material-icons md-18">content_copy</span>&#8203</button>')
            .on('click', (e) => {
                e.preventDefault();
                navigator.clipboard.writeText(adData());
            }).prependTo($actionContainer);
    }
}

// Observer starten
const observer = new MutationObserver(() => {
    // Wir prüfen bei jeder Änderung, ob unsere UI noch da ist
    initUI();
});

// Wir beobachten den gesamten Body auf Änderungen (Unterelemente und Kind-Elemente)
observer.observe(document.body, {
    childList: true,
    subtree: true
});

// Einmalig initial starten (falls DOM schon fertig ist)
$(document).ready(() => {
    initUI();
});


// --- Helper Functions ---

function adData() {
    const name = $('.profile__card-display-name').first().html();
    const phone = "";
    const text = $('.profile__description-detail').first().text();
    const URL = window.location.href;
    const address = $('.profile__card-location .location-wrapper')
        .first().text()
        .replace(/ - .*$/, '')
        .replace(/\n/g, ' ')
        .replace(/\s+/g, ' ')
        .trim();
    let service = '';
    $('.static-tag--light').each(function() {
        if (service.length) service += ', ';
        service += $(this).text();
    });
    let taboo = '';
    $('.static-tag--grey').each(function() {
        if (taboo.length) taboo += ', ';
        taboo += $(this).text();
    });

    const user = $('.user').first().text();
    const figure = $('.figure').first().text();
    const breast = $('.breast').first().text();
    const origin = $('.origin').first().text();
    const languages = $('.languages').first().text();
    const others = $('.others').first().text();
    const hair = $('.hair').first().text();
    const preferred = $('.profile__preferred-data-text').first().text();
    let dataHTML = `Infoservice\n[QUOTE][URL=${URL}][B]${name}[/B][/URL]\n\n[SIZE="1"]${text}\n\n`;
    if (phone.length) {
        const rawPhone = phone.replace(/ /g, '').replace(/\+49\(0\)/, '0');
        const phone2 = rawPhone.replace(/[/\-]/g, '');
        const phone3 = phone2.replace(/^0([1-9])/, '+49$1');
        dataHTML += `[B]Telefon:[/B] ${rawPhone}, ${phone2}, ${phone3}\n`;
    }
    const addressURL = address.replace(/ /g, '%20');
    dataHTML += `[B]Daten:[/B] ${user}, ${figure}, ${others}, Brust: ${breast}, Intim: ${hair}, Herkunft: ${origin}, Sprachen: ${languages}\n`
        + `[B]Date-Wünsche:[/B] ${preferred}\n`
        + `[B]Adresse:[/B] [URL=https://www.google.de/maps/place/${addressURL}]${address}[/URL]\n`
        + `[B]Service:[/B] ${service}\n`;
    if (taboo.length) dataHTML += `[B]Tabus:[/B] ${taboo}\n`;
    dataHTML += `[/SIZE][/QUOTE]`;
    dataHTML = dataHTML.replace(/ {2,}/g, ' ').replace(/\n{3,}/g, '\n\n');
    return dataHTML;
}

function startDLALL(username) {
    const downloadlist = [];
    $('.profile__gallery-thumb-list .image-img').each(function() {
        const link = $(this).attr('src')
            .replace(/-\d+\.(jpg|webp)/i, '-o.$1') /* use original size */
            .replace(/\.webp$/, '.jpg'); /* download JPG instead of WEBP */
        if (link.includes('/mask/')) return; /* skip blurred preview images */
        downloadlist.push(link);
        console.log(link);
    });
    const name = artistname();
    let path = name;
    if (name.toLowerCase() !== username.toLowerCase()) path += `,${username}`;
    dlAll(path, [...new Set(downloadlist)]);
}

function dlAll(path, downloadlist) {

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

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

        console.log([url, file]);

        GM_download({
            url: url,
            name: file,
            saveAs: false,
            onerror(err) {
                $line.append(`<span class="download_error">ERROR: ${err.error}<br>${err.details}</span>`);
            },
            onload() {
                $line.append('<span class="download_ok">✓</span>');
            }
        });
    }
}

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: 85px;
    overflow: visible;
    z-index: 10000;
}
.KMImgDLerLogo {
    position: absolute;
    color: white;
    font-size: 11px;
    top: 21px;
    left: 32px;
}
.material-icons {
    position: relative;
    top: 6px;
}`);
}