MLB The Show Nation Profit Reporter

Calculates the current profitability of a card and auto-fills the text box for Buy/Sell Orders with +/- 1 Stub. DOES NOT AUTOMATE ORDERS AND NEVER WILL!

Mint 2017.06.11.. Lásd a legutóbbi verzió

// ==UserScript==
// @name         MLB The Show Nation Profit Reporter
// @namespace    https://greasyfork.org/en/users/8332-sreyemnayr
// @version      2017.06.11
// @description  Calculates the current profitability of a card and auto-fills the text box for Buy/Sell Orders with +/- 1 Stub.  DOES NOT AUTOMATE ORDERS AND NEVER WILL!
// @author       sreyemnayr
// @match        http://theshownation.com/marketplace/listing*
// @match        http://www.theshownation.com/marketplace/listing*
// @grant        unsafeWindow
// ==/UserScript==


(function() {
    'use strict';
    
    var scatterChart = unsafeWindow.scatterChart;
    var dates = [];
    for(var i=0,l=scatterChart.data.datasets.length;i<l;i++){ var ds = scatterChart.data.datasets[i]; for(var ii=0, ll=ds.data.length;ii<ll;ii++){ var d = ds.data[ii]; var dte = new Date(d.x); dte.setHours(dte.getHours()+2); dates.push(dte); } }
    var numHour = 0;
    var numThreeHours = 0;
    var numToday = 0;
    var now = new Date(Date.now());
    var today = new Date(Date.now());
    today.setHours(0);
    var OneHourAgo = now;
    OneHourAgo.setHours(now.getHours()-1);
    for(var iii=0,lll=dates.length;iii<lll;iii++){
    if(dates[iii] > OneHourAgo)
    {
        numHour++;

    }
    if(dates[iii] > now-(1000*60*60*3))
    {
        numThreeHours++;

    }
    if(dates[iii] > today)
    {
        numToday++;

    }
    }

    $('.quick-actions').each(
        function(i){

                    var buyNowPrice = parseInt($(this).find('ul li form[action="/marketplace/create_buy_now"] input[name="price"]').val().replace(/,/g, ""));
                    var sellNowPrice = parseInt($(this).find('ul li form[action="/marketplace/create_sell_now"] input[name="price"]').val().replace(/,/g, ""));

            var li = document.createElement('li');
                    var btn = document.createElement('button');
                    btn.appendChild(
                        document.createTextNode(
                            numHour + " this hour, " + numToday + " today"
                        )
                    );
                    btn.className = 'btn btn-info';
                    li.appendChild(btn);
                    this.getElementsByTagName('ul')[0].insertBefore(li, this.getElementsByTagName('ul')[0].firstChild );

            $(this).find('form[action="/marketplace/create_buy_order"] input[name="price"]').val(sellNowPrice + 1);
            $(this).find('form[action="/marketplace/create_sell_order"] input[name="price"]').val(buyNowPrice - 1);
                    li = document.createElement('li');
                    btn = document.createElement('button');
                    btn.appendChild(
                        document.createTextNode(
                            parseInt(buyNowPrice * 0.90 - sellNowPrice) +
                            " profit"
                        )
                    );
                    btn.className = 'btn btn-success';
                    li.appendChild(btn);
                    this.getElementsByTagName('ul')[0].insertBefore(li, this.getElementsByTagName('ul')[0].firstChild );

            $(this).find('form[action="/marketplace/create_buy_order"] input[name="price"]').val(sellNowPrice + 1);
            $(this).find('form[action="/marketplace/create_sell_order"] input[name="price"]').val(buyNowPrice - 1);
        }
    );

})();