MLB The Show Nation Order Helper

Detects if your orders are outbid

目前為 2017-05-23 提交的版本,檢視 最新版本

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

(function() {
    'use strict';
    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 = "";
        $.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, ""));

            

            if(myBuyPrice < thisSellNowPrice)
            {
                this.className = 'btn btn-warning';
                $($(this).parent().parent().children()[2]).append("<br /><span 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+"</span>");
            }
            else
            {
                this.className = 'btn btn-success';
            }

        });

    });

       $(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 = "";
        $.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, ""));

            
            if(mySellPrice > thisBuyNowPrice)
            {
                this.className = 'btn btn-warning';
                $($(this).parent().parent().children()[2]).append("<br /><span 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+"</span>");
            }
            else
            {
                this.className = 'btn btn-success';
            }

        });

    });

})();