MarktEnhancer

Usability fixes

目前為 2021-02-12 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

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