MarktEnhancer

Usability fixes

Versione datata 12/02/2021. 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         MarktEnhancer
// @namespace https://greasyfork.org/users/290665
// @version      1.2.1
// @description  Usability fixes
// @match        https://*.markt.de/*
// @grant    GM_addStyle
// @grant    GM_download
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// ==/UserScript==

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

var dlname;

$(function() {

    var phone = decPh($('#clsy-c-expose-phone-number').data('phone'));
//    console.log("phone: ",$('#clsy-c-expose-phone-number').data('phone')," -> ",phone);

    if (phone.length) {
        phone = phone.replace(/\+ +/,'+');
        var url = phone.replace(/[ -]+/g,'');
        var search = phone.replace(/ +/g,'%20');
    }
    var PHONE = phone;
    PHONE = PHONE.replace(/\+49 ?/,'0').replace(/ \/ /,'-');


    var NAME = $('#clsy-c-expose-header').first().text();
    if ($('.clsy-c-userbox__profile-name').length) {
        NAME = $('.clsy-c-userbox__profile-name').text() + " - " + NAME;
    }
    NAME = NAME.replace(/ß/,'ss')
        .replace(/[^\w-\(\)äöü ]/ig,'')
        .replace(/\b(scharfe?|neue?|[dw]ie|[wd]er|[wd]as|und|[dz]u|sie|in|add?resse|m[üu]e?nchen|geile?|mit|aus|mega|service|original|100|(ph|f)otos?|top|private?)\b/ig,'')
        .replace(/ +/g,' ')
        .replace(/(^ | $)/g,'')
        .substring(0,64);

    dlname = NAME + ' - ' + PHONE;
    var dlArea = $('<div id="markt-enhancer"><button id="dlbutton">Download <b>'+dlname+'</b></button><div class="me-logo">MarktEnhancer '+myVersion+'</div><div class="dl-area"></div></div>');

    $('body').on('click', '#dlbutton', function(event) {
        start();
        event.stopPropagation();
        event.preventDefault();
    });

    $('#clsy-c-expose').append(dlArea);
});


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;
}

#markt-enhancer {
    max-height: 150px;
    overflow: auto;
    background-color: rgb(140, 65, 92);
    padding: 4px;
    font-size: 10px;
    position: absolute;
    left: 180px;
    top: 0px;
    z-index: 10;
    right: 180px;
    color: white;
}

#markt-enhancer button {
    background-color: #f39a00;
    font-size: 10px;
    border: 2px outset;
    padding: 4px;
    float: right;
    border-color: white;
}

#markt-enhancer dl-area {
    column-count: 2;
}
`);
}


function start() {
    var downloadlist = [];
    $('[data-fancybox]').each(function() {
        var link = $(this).attr('href');
        if (link.length) {
            downloadlist.push(link);
        }
    });
    dlAll(dlname,downloadlist);
}

function dlAll(path,downloadlist) {

    var dialog = $('<div id="markt-enhancerdialog" title="Download to '+path+' ..."></div>').appendTo($('#markt-enhancer'));

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

        (function(url,filepath,filename,linediv) {
          /*  console.log(url);
            console.log(filepath);
            console.log(filename); */
            var dl = GM_download({
                url: url,
                name: filepath,
                saveAs: false,
                onerror: function(err){
                    $(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 decPh(input) {
    return input.replace(/A/g,'8').replace(/B/g,'4').replace(/C/g,'7').replace(/D/g,'1').replace(/E/g,'9').replace(/F/g,'6').replace(/G/g,'0').replace(/H/g,'5').replace(/I/g,'3').replace(/J/g,'2');
}