Mardaneus86 / futwebapp-tampermonkey

TamperMonkey scripts to enhance the FUT 21 Web App - Discontinued
MIT License
192 stars 103 forks source link

Help me with bag #11

Closed Qeekly closed 7 years ago

Qeekly commented 7 years ago

Tell me how to change the script so that I get the price twice (or better in one) when I click the button, and not three, as now. That is, the problem is this: I click on the button and the price is received, then after a time there are two more price updates. How to fix it? I'm strong in php, java, but not strong at js.

For myself, I rewrote a bit of code for my style and added a few useful features that I need.

(function () {
  'use strict';

    $(document).bind('DOMNodeInserted', function(event) {

        var playerImageUrl;
        var playerId;

        if($(event.target).hasClass('DetailPanel')) {

            if($(event.target).find('#getMinBuyNowPrice').length === 0) {

                $(event.target).find('.bidOptions').append('<button id="getMinBuyNowPrice" class="list"><span class="btn-text">Buy Now (min.)</span><span class="btn-subtext coins" id="minBuyNow">Get Price</span></button>');
                $(event.target).find('.QuickListPanel').append('<button id="getMinBuyNowPrice" class="list"><span class="btn-text">Buy Now (min.)</span><span class="btn-subtext coins" id="minBuyNow">Get Price</span></button>');

            }

            $('.listFUTItem').click(function () {

                $('#minBuyNow').text('Get Price');

            });

            $('#getMinBuyNowPrice').click(function () {

                if($('body').find('.squadSlot').length === 0) {

                    playerImageUrl = $('.listFUTItem.selected').find('.photo').attr('src');

                } else {

                    playerImageUrl = $('.squadSlot.ui-slot-selected').find('.photo').attr('src');

                }

                playerId = playerImageUrl.substr(playerImageUrl.lastIndexOf('/') + 1).replace('.png', '');
                search(playerId, 9999999999).observe(this, handleSearch);

            });

        }

    });

    var minimumBIN = 9999999999;
    var maskedDefId = 0;
    var handleSearch = function handleSearch(t, data) {
    var lowestBIN;
    var player;

        if(data.items.length > 0) {

            var newMinimumBIN = Math.min.apply(Math, data.items.map(function (o) { return o._auction.buyNowPrice; }));

            if(newMinimumBIN < minimumBIN) {

                minimumBIN = newMinimumBIN;
                $('#minBuyNow').text(minimumBIN);

                var random_time = Math.random()*(17000 - 8000 + 1) + 8000;
                setTimeout(function () { search(maskedDefId, minimumBIN).observe(this, handleSearch); }, random_time);

            } else {

                lowestBIN = Math.min.apply(Math, data.items.map(function (o) { return o._auction.buyNowPrice; }));
                player = repositories.Item.getStaticDataByDefId(maskedDefId);

                $('#minBuyNow').text(lowestBIN);

          }

        } else {

            lowestBIN = Math.min.apply(Math, data.items.map(function (o) { return o._auction.buyNowPrice; }));
            player = repositories.Item.getStaticDataByDefId(maskedDefId);
            $('#minBuyNow').text(lowestBIN);
        }

    };

    var search = function search(playerId, maxBuy) {

        minimumBIN = maxBuy;
        maskedDefId = playerId;

        if(maxBuy === 9999999999) {

            maxBuy = 0;

        }

        var searchCriteria = new transferobjects.SearchCriteria();
        searchCriteria.type = enums.SearchType.PLAYER;
        searchCriteria.defId = [maskedDefId];
        searchCriteria.maxBuy = maxBuy;

        return repositories.TransferMarket.search(searchCriteria);

    };

})();
Mardaneus86 commented 7 years ago

Searching the minimum BIN price based on the market uses the following algorithm:

  1. Initial search without a max buy now amount
  2. Get the lowest buy now value of the result
  3. Start a new search with the lowest buy now value found
  4. Go to step 2 until there are no more items found

That means that multiple market searches are required in order to find the lowest BIN price for a specific player.

Qeekly commented 7 years ago

It seems to me that this is not a very correct algorithm because the EA eye can keep track of frequent requests. Probably need to come up with some kind of algorithm, so that we can make a random delay in each of the items. That is, the first item was fulfilled - a delay of 5 seconds, the second point - 3 seconds, the third - 3 seconds and the fourth final - 8 seconds for example. Do you have any thoughts on this matter? I'm very concerned about the safety my and other players.

Mardaneus86 commented 7 years ago

Why wouldn't that algorithm be correct? See this line in the script. It waits for 2 seconds between each request.

This could be made random, eg:

var delay = (Math.floor(Math.random() * 1) + 3) * 1000; // between 1 and 4 seconds

I initially created this script because Futbin didn't give any BIN prices yet, but now it does so this script might even be considered obsolete.

Qeekly commented 7 years ago

Futbin give not actual price. Price for Buy Now changing from min to min. And this script need random delay when work. I think 2-4 seconds it so small for delay script if we want emulate human in WebApp.