网易 buff 增强脚本

比例计算 成交量显示 销售价显示

当前为 2020-11-02 提交的版本,查看 最新版本

// ==UserScript==
// @name         网易 buff 增强脚本
// @namespace    out
// @version      0.14
// @description  比例计算 成交量显示 销售价显示
// @author       bluebird
// @match        *://buff.163.com/market/goods*
// @grant        GM_addStyle
// @grant        GM_openInTab
// @grant        GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @require      https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
// @connect      steamcommunity.com
// @supportURL   https://steamcommunity.com/id/bluebird2333/
// ==/UserScript==

const $ = window.jQuery;



(function() {
    'use strict';
    // Your code here...
    $(document).ready(function(){
        run();
    });

    // Your code here...
})();


var volumeNum = 0
var data

function run(){
    let marketUrl = $('div.detail-summ > a').attr("href")


    getItemVolume(marketUrl)
}

function calc(data){

    console.log(data)
    if(data){
        GM_addStyle(` .detail-cont > div.blank20 { height:5px;}
                                              .detail-summ span { display:none; margin-right:0px; }
                                              ..detail-summ a { float:right }
                                               .pricelist {font-size: 0.75rem; float:left}
                                               .red {color:red}
                                               .warn {font-size: 0.75rem;float:right}
                                                .yellow {color:yellow}
                                           `);

        if(!data.lowest_sell_order&&!data.highest_buy_order){
            return;
        }
        let lowest =  parseInt(data.lowest_sell_order)/100
        let highest = parseInt(data.highest_buy_order)/100
        let calcLow = calcfee(parseInt(data.lowest_sell_order))/100
        let calcHigh = calcfee(parseInt(data.highest_buy_order))/100
        let  siteprice = getFloat($("table a.i_Btn:first").attr('data-price'));
        if(!siteprice){
            siteprice = getFloat($("table strong.f_Strong:first").text() + $("table strong.f_Strong:first small").text());
        }

        let lowRatio = (siteprice/calcLow).toFixed(2)
        let highRatio = (siteprice/calcHigh).toFixed(2)

        var info = "<div><ul class='pricelist'><li>24小时出售量 :"+volumeNum.toString()+"</li><li  class='yellow'>最高收购价格"+highest.toString()+"        比例:"+highRatio.toString()+"</li><li class='yellow'>最低出售价格"+lowest.toString()+"       比例:"+lowRatio.toString()+"</li>"

        let priceRange = (siteprice/20).toFixed(2)

        let buyPriceMap = {1:0,2:0}
        let stableBuyPrice = 0
        let buy_order_graph = data.buy_order_graph
        var tmp = 0
        for (let i = 0; i < buy_order_graph.length; i++) {
            let spread =  highest - buy_order_graph[i][0]
            let itemNum = buy_order_graph[i][1]
            let rangeNum = Math.trunc(spread/priceRange)+1
            if(rangeNum>3){
                break
            }
            buyPriceMap[rangeNum]  += (itemNum-tmp)
            if((itemNum-tmp)>=5 & stableBuyPrice===0){
                stableBuyPrice = buy_order_graph[i][0]
            }
            tmp = itemNum

        }
        if( stableBuyPrice!=0){
            info = info + "<li>最高稳定收购价格:"+stableBuyPrice.toString()+" 比例:"+(siteprice*100/calcfee(stableBuyPrice*100)).toFixed(2)+"</li>"
        }
        let sellPriceMap = {1:0,2:0}
        let stableSellPrice = 0
        let sell_order_graph = data.sell_order_graph
        tmp = 0
        for (let i = 0; i < sell_order_graph.length; i++) {
            let spread =  sell_order_graph[i][0] - lowest
            let itemNum = sell_order_graph[i][1]
            let rangeNum = Math.trunc(spread/priceRange)+1
            if(rangeNum>3){
                break
            }
            sellPriceMap[rangeNum]  += (itemNum-tmp)
            if((itemNum-tmp)>=5 & stableSellPrice===0){
                stableSellPrice = sell_order_graph[i][0]
            }
            tmp = itemNum

        }
        if(stableSellPrice !=0){
           info = info + "<li>最低稳定出售价格:"+stableSellPrice.toString()+" 比例:"+(siteprice*100/calcfee(stableSellPrice*100)).toFixed(2)+"</li>"
        }
        info = info+"</ul></div>"

        info = info+"<div class='warn'> <ul>"
        if(highRatio>0.8){
            info = info + "<li class='red'>比例过低</li>"
        }

        if(volumeNum<100){
            info = info + "<li class='red'>每日销售量过低请谨慎购买</li>"
        }
        if(buyPriceMap[1]<5){
            info = info + "<li class='red'>目前最高收购价格区间(5%)仅有"+buyPriceMap[1].toString()+"件请谨慎购买</li>"
        }

        if(sellPriceMap[1]<5){
            info = info + "<li class='red'>目前最低出售价格区间(5%)仅有"+sellPriceMap[1].toString()+"件请谨慎购买</li>"
        }
        info = info+"</ul></div>"


        $("div.detail-summ").prepend(info)




    }


}


function getItemVolume(marketUrl){
    let oriLink = marketUrl.split('/');
    let appid = oriLink[oriLink.length-2];
    oriLink = oriLink[oriLink.length-1];
    GM_xmlhttpRequest({
        method: "get",
        url: `https://steamcommunity.com/market/priceoverview/?appid=${appid}&market_hash_name=${oriLink}`,
        responseType: "json",
        timeout: 5000,
        onload: function (result) {
            result = result.response;
            if(result.volume){
                volumeNum = parseInt(result.volume.replace(/\, ?/gi, ''))
            }else{
                volumeNum =0
            }

            getPriceData(marketUrl)

        }
    });
}

function getPriceData(marketUrl){
    GM_xmlhttpRequest({
        method: "GET",
        url: marketUrl,
        timeout:5000,
        onload: function(res){
            console.log("req ok ")
            if(res.status == "200" &&res.responseText!=="null"){
                console.log("req  status ok ")
                try{
                    var nameid = res.responseText.match(/Market_LoadOrderSpread\( (\d+)/)[1];
                }
                catch(err){
                    if(res.responseText.indexOf('market_listing_nav_container') != -1){
                        // steamxj();
                        return;
                    }
                }
            }
            GM_xmlhttpRequest({
                timeout:5000,
                method: "GET",
                url: "https://steamcommunity.com/market/itemordershistogram?country=CN&language=schinese&currency=23&item_nameid=" + nameid,
                responseType: "json",
                onload: function(data){
                    var obj = data.response;
                    data = obj
                    calc(data)
                }
            }
                             )
        }
    }
                     )
}


function calcfee(p){
    // return p
    var pnofee = Math.max(Math.floor(p/1.15),1);
    var vfee = Math.max(Math.floor(pnofee*0.1),1);
    var pfee = Math.max(Math.floor(pnofee*0.05),1);
    while((pnofee + vfee + pfee) != p) {
        if((pnofee + vfee + pfee) > p) {
            pnofee--;
        }
        if((pnofee + vfee + pfee) < p) {
            pnofee++;
        }
        vfee = Math.max(Math.floor(pnofee*0.1),1);
        pfee = Math.max(Math.floor(pnofee*0.05),1);
    }
    return pnofee;
}



function getFloat(str){
    try{
        var f = parseFloat(str.match(/[\d]{1,}(\.\d+)?/)[0]);
    }
    catch(err){
        return 0;
    }
    return f;

}