Greasy Fork is available in English.

HWM подсчет ЦЗБ для каждого лота на рынке

Цена за бой с учетом оптислома! Учитывает стоимость крафта.

// ==UserScript==
// @name           HWM подсчет ЦЗБ для каждого лота на рынке
// @description    Цена за бой с учетом оптислома! Учитывает стоимость крафта.
// @description    если арт открыт первый раз со скриптом то его цена не известна. Надо обновить страницу и все будет ок
// @include        https://*heroeswm.ru/auction.php*
// @include        http://178.248.235.15/auction.php*
// @include        http://209.200.152.144/auction.php*
// @include        https://*lordswm.com/auction.php*
// @require        https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @version        1.0
// @grant          GM_getValue
// @grant          GM_setValue
// @namespace https://greasyfork.org/users/237404
// ==/UserScript==

var urlHWM = 'https://www.heroeswm.ru/';

var get_data = function(url, callback, param) {

    var request = new XMLHttpRequest();

    request.onreadystatechange = function()
    {
        if (request.readyState == 4 && request.status == 200)
        {
            callback(request.responseText, param);
        }
    };

    request.open('GET', url);
    request.send();

};

var arts = [];
$('.wb[bgcolor="#ffffff"],.wb[bgcolor="#eeeeee"]').each(function(e,i){
    var artKey = $(this).find('a[name]:first').attr('name');
    var art = [];
    art.image = $(this).find('.cre_mon_image2').attr('src').split('/');
    art.image = art.image[ art.image.length-1 ];
    if( parseInt( GM_getValue( "remont"+art.image ) ) > 0 ){
        art.remont = parseInt( GM_getValue( "remont"+art.image ) );
    }else{
        art.url = $(this).find('.cre_mon_image2').closest('a').attr('href');
    }
    art.durability1 = parseInt( $(this).find('.art_durability_hidden').html().split('/')[0] );
    art.durability2 = parseInt( $(this).find('.art_durability_hidden').html().split('/')[1] );
    art.kraft = kraftPrice( $(this).find('.cre_mon_image2').attr('title') );

    art.price = parseInt( $(this).find('td:eq(4) table div table td:eq(1)').html().replace(',', '') );
    arts[ artKey ] = art;
});
console.log( arts );

for (var artKey in arts) {
    var art = arts[artKey];
    if( !art.remont ){
        get_data(art.url, art_parse, art.image);
    }else{
        var res = smith( art.price, 0, art.remont, 90, 100, art.kraft, art.durability1, art.durability2);
        $('a[name="'+artKey+'"]').parent().append( '<div style="text-align:right;">Боев: '+res.optb+'&nbsp;&nbsp; ЦЗБ: <b>'+res.od+'</b></div>' );
        //$('a[name="'+artKey+'"]').closest('.wb').css('order', parseInt( res.od*100 ) );
    }
}

/*$('.wb[bgcolor="#ffffff"]').parent().css({
    'display': 'flex',
    'flex-direction': 'column'
});*/

function kraftPrice( x ){
    var price = 0;
    var paraPrice = {
        'I' : 3196,
        'E' : 2470,
        'A' : 2422,
        'W' : 1680,
        'F' : 2175
    };
    for( var pp in paraPrice ){
        var mod = pp;
        var para = paraPrice[pp];
        //console.log( mod, modCenaPara );
        if( x.indexOf(mod+'12') > 0 ){ price += para * 45;
        }else if( x.indexOf(mod+'11') > 0 ){ price += para * 37;
        }else if( x.indexOf(mod+'10') > 0 ){ price += para * 30;
        }else if( x.indexOf(mod+'9') > 0 ){ price += para * 24;
        }else if( x.indexOf(mod+'8') > 0 ){ price += para * 19;
        }else if( x.indexOf(mod+'7') > 0 ){ price += para * 15;
        }else if( x.indexOf(mod+'6') > 0 ){ price += para * 12;
        }else if( x.indexOf(mod+'5') > 0 ){ price += para * 9;
        }else if( x.indexOf(mod+'4') > 0 ){ price += para * 6;
        }else if( x.indexOf(mod+'3') > 0 ){ price += para * 4;
        }else if( x.indexOf(mod+'2') > 0 ){ price += para * 2;
        }else if( x.indexOf(mod+'1') > 0 ){ price += para * 1;
        }
    }
    return price;
}

function art_remont_by_url( url ){
    return get_data(url, art_parse);
}
function art_parse( html, image ){
    var re = /(class\=wblight)(.*)(gold\.png)(.*)<td>([\,\d]+)<\/td>/sgi;
    var m = re.exec(html);

    var remont = parseInt( m[5].replace(',','') );
    GM_setValue('remont'+image, remont);

    for (var artKey in arts) {
        var art = arts[artKey];
        if( !art.remont && art.image == 'image' ){
            arts[artKey] = remont;
        }
    }
}


/* спизженно на молоте ведьм http://www.witchhammer.ru/viewpage.php?page_id=19 */
function smith(art_price,sell_price,base_repair_price,repair_quality=90,blacksmith_price=100,kraft_cost=0,current_durability,max_durability) {
    function p_p_b(cd, bd, md, each_type) {
        var tmp_arr = new Array(),
        curr_sell = 0,
        od = 1000000,
        opt = 1000000,
        ppb = Math.round((art_price - sell_price + kraft_cost) / cd * 1000),
        battle_count = 0;
        for (i = md; i > 0; i--) {
            cost = (art_price - sell_price + kraft_cost + base_repair_price * blacksmith_price / 100 * (md - i));
            if (i == md) battle_count = cd;
            else battle_count += Math.floor((i + 1) * repair_quality / 100);
            ppb = Math.round(cost / battle_count * 100) / 100;
            tmp_arr.push(new Array(ppb, i));
            if (opt >= ppb) {
                opt = ppb;
                od = battle_count;
                opt_pr = i;
            }
        }
        old_durability = cd;
        return {
            'cd': battle_count,
            'od': opt,
            'ppb': ppb,
            'optb': od,
            'opt_pr': opt_pr,
            'tmparr': tmp_arr
        };
    }

    return p_p_b(current_durability, max_durability, max_durability);
}