MLB The Show Nation Order Helper

Detects if your orders are outbid

目前為 2017-06-07 提交的版本,檢視 最新版本

// ==UserScript==
// @name         MLB The Show Nation Order Helper
// @namespace    https://greasyfork.org/en/users/8332-sreyemnayr
// @version      2017.6.3.1
// @description  Detects if your orders are outbid
// @author       sreyemnayr
// @match        http://theshownation.com/marketplace/orders
// @match        http://www.theshownation.com/marketplace/orders
// @grant        none
// ==/UserScript==

function orderHelper(){
    $('.helperDiv').remove();
var tables = $('.marketplace-search');
    var buy_orders = tables[0];
    var sell_orders = tables[1];

    $(buy_orders).find('a').each(function(i){
       var url = $(this).attr('href');
       var myBuyPrice = parseInt($($(this).parent().parent().children()[2]).text());
        var thisBuyNowPrice = "";
        var thisSellNowPrice = "";
        var profitMargin = "";
        $.ajax({url:url, context:this}).done(function(b){
            thisBuyNowPrice = parseInt($(b).find('.quick-actions form[action="/marketplace/create_buy_now"] input[name="price"]').val().replace(/,/g, ""));
            thisSellNowPrice = parseInt($(b).find('.quick-actions form[action="/marketplace/create_sell_now"] input[name="price"]').val().replace(/,/g, ""));
            profitMargin = parseInt(thisBuyNowPrice * 0.90 - thisSellNowPrice);

            if(myBuyPrice < thisSellNowPrice)
            {
                this.className = 'btn btn-warning';
                $($(this).parent().parent().children()[2]).append("<div class=\"helperDiv\" style=\"background-color:yellow\">Outbid at <img class=\"currency-icon-small\" src=\"https://s3.amazonaws.com/mlb17-shared/dist/3/img/stub-icon.png\"> "+thisSellNowPrice+"</div>");
            }
            else
            {
                this.className = 'btn btn-success';
            }
            $($(this).parent().parent().children()[1]).append("<div class=\"helperDiv\"><span style=\"background-color:white; font-size:80%\">"+
                                                              "Buy Now: <img class=\"currency-icon-small\" src=\"https://s3.amazonaws.com/mlb17-shared/dist/3/img/stub-icon.png\" style=\"width:15%; height:15%;\"> "+
                                                              thisBuyNowPrice+
                                                              "</span><br /><span style=\"background-color:white; font-size:80%\">Sell Now: <img class=\"currency-icon-small\" src=\"https://s3.amazonaws.com/mlb17-shared/dist/3/img/stub-icon.png\" style=\"width:15%; height:15%;\"> "+
                                                              thisSellNowPrice+
                                                              "</span><br /><span style=\"background-color:white; font-size:80%\">Profit: <img class=\"currency-icon-small\" src=\"https://s3.amazonaws.com/mlb17-shared/dist/3/img/stub-icon.png\" style=\"width:15%; height:15%;\"> "+
                                                              profitMargin+"</span></div>");

        });

    });

       $(sell_orders).find('a').each(function(i){
       var url = $(this).attr('href');
       var mySellPrice = parseInt($($(this).parent().parent().children()[2]).text());
        var thisBuyNowPrice = "";
        var thisSellNowPrice = "";
           var profitMargin = "";
        $.ajax({url:url, context:this}).done(function(b){
            thisBuyNowPrice = parseInt($(b).find('.quick-actions form[action="/marketplace/create_buy_now"] input[name="price"]').val().replace(/,/g, ""));
            thisSellNowPrice = parseInt($(b).find('.quick-actions form[action="/marketplace/create_sell_now"] input[name="price"]').val().replace(/,/g, ""));
            profitMargin = parseInt(thisBuyNowPrice * 0.90 - thisSellNowPrice);
console.log('mySell: ',mySellPrice,' thisBuy: ',thisBuyNowPrice);
            if(mySellPrice > thisBuyNowPrice)
            {
                this.className = 'btn btn-warning';
                $($(this).parent().parent().children()[2]).append("<div class=\"helperDiv\" style=\"background-color:yellow\">Outbid at <img class=\"currency-icon-small\" src=\"https://s3.amazonaws.com/mlb17-shared/dist/3/img/stub-icon.png\"> "+thisBuyNowPrice+"</div>");
            }
            else
            {
                this.className = 'btn btn-success';
            }
            $($(this).parent().parent().children()[1]).append("<div class=\"helperDiv\"><span style=\"background-color:white; font-size:80%\">"+
                                                              "Buy Now: <img class=\"currency-icon-small\" src=\"https://s3.amazonaws.com/mlb17-shared/dist/3/img/stub-icon.png\" style=\"width:15%; height:15%;\"> "+
                                                              thisBuyNowPrice+
                                                              "</span><br /><span style=\"background-color:white; font-size:80%\">Sell Now: <img class=\"currency-icon-small\" src=\"https://s3.amazonaws.com/mlb17-shared/dist/3/img/stub-icon.png\" style=\"width:15%; height:15%;\"> "+
                                                              thisSellNowPrice+
                                                              "</span><br /><span style=\"background-color:white; font-size:80%\">Profit: <img class=\"currency-icon-small\" src=\"https://s3.amazonaws.com/mlb17-shared/dist/3/img/stub-icon.png\" style=\"width:15%; height:15%;\"> "+
                                                              profitMargin+"</span></div>");

        });

    });
}

(function() {
    'use strict';
    orderHelper();
    setInterval(orderHelper,15000);

})();