Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name FUT20 Autobuyer
- // @namespace http://tampermonkey.net/
- // @version 0.6
- // @updateURL https://github.com/Vivalemuc/futtamper/blob/master/fut_autobuyer.js
- // @description try to take over the world!
- // @author Vivalemuc
- // @match https://www.easports.com/uk/fifa/ultimate-team/web-app/*
- // @match https://www.easports.com/fifa/ultimate-team/web-app/*
- // @grant none
- // @require http://code.jquery.com/jquery-3.4.1.min.js
- // ==/UserScript==
- (function() {
- 'use strict';
- window.getMaxSearchBid = function(min, max) {
- return Math.round((Math.random() * (max - min) + min) / 1000) * 1000;
- };
- window.getMinSearchBid = function() {
- var wait = [100, 800];
- if (jQuery('#ab_min_bid_range').val() !== '') {
- wait = jQuery('#ab_min_bid_range').val().split('-');
- }
- var bid = Math.round((Math.random() * (wait[1] - wait[0]) + wait[0]) / 100) * 100;
- return bid;
- };
- window.searchCount = 0;
- window.initStatistics = function() {
- window.futStatistics = {
- soldItems: '-',
- unsoldItems: '-',
- activeTransfers: '-',
- availableItems: '-',
- coins: '-',
- };
- window.timers = {
- updatePrice: window.createTimeout(0, 0),
- search: window.createTimeout(0, 0),
- coins: window.createTimeout(0, 0),
- transferList: window.createTimeout(0, 0),
- };
- };
- window.bids = [];
- window.playersNotDesired = [];
- window.createTimeout = function(time, interval) {
- return {
- start: time,
- finish: time + interval,
- };
- };
- window.processor = window.setInterval(function() {
- if (window.autoBuyerActive) {
- var time = (new Date()).getTime();
- if (window.timers.search.finish == 0 || window.timers.search.finish <= time) {
- if(window.updatePrice){
- window.updateFutMarket(null, null, null);
- window.timers.search = window.createTimeout(time, window.getRandomWaitForUpdatePrice());
- }else{
- window.searchFutMarket(null, null, null);
- window.timers.search = window.createTimeout(time, window.getRandomWait());
- }
- }
- if (window.timers.coins.finish == 0 || window.timers.coins.finish <= time) {
- window.futStatistics.coins = services.User.getUser().coins.amount.toLocaleString();
- window.timers.coins = window.createTimeout(time, 2500);
- }
- if (window.timers.transferList.finish == 0 || window.timers.transferList.finish <= time) {
- window.updateTransferList();
- window.timers.transferList = window.createTimeout(time, 30000);
- }
- } else {
- window.initStatistics();
- }
- window.updateStatistics();
- }, 500);
- window.searchFutMarket = function(sender, event, data) {
- if (!window.autoBuyerActive) {
- return;
- }
- services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
- type: PIN_PAGEVIEW_EVT_TYPE,
- pgid: "Transfer Market Search",
- });
- var searchCriteria = getAppMain().getRootViewController().getPresentedViewController().getCurrentViewController().getCurrentController()._viewmodel.searchCriteria;
- searchCriteria.maxBid = window.getMaxSearchBid(300000, 800000);
- searchCriteria.minBid=window.getMinSearchBid();
- if(searchCriteria.level === "SP" && searchCriteria.minBuy === 0){
- searchCriteria.minBuy=10500;
- }
- if(window.modifier<=1.0){
- searchCriteria.maxBuy=window.sellPrice
- }
- services.Item.clearTransferMarketCache();
- services.Item.searchTransferMarket(searchCriteria, 1).observe(this, (function(sender, response) {
- if (response.success) {
- var explode = function(){
- services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
- type: PIN_PAGEVIEW_EVT_TYPE,
- pgid: "Transfer Market Results - List View",
- });
- if(response.data.items.length>0){
- services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
- type: PIN_PAGEVIEW_EVT_TYPE,
- pgid: "Item - Detail View",
- });
- }
- };
- setTimeout(explode, 1000);
- writeToDebugLog('Received ' + response.data.items.length + ' items');
- var maxPurchases = 3;
- if ($('#ab_max_purchases').val() !== '') {
- maxPurchases = Math.max(1, parseInt($('#ab_max_purchases').val()));
- }
- response.data.items.sort(function(a, b) {
- var priceDiff = a._auction.buyNowPrice - b._auction.buyNowPrice;
- if (priceDiff != 0) {
- return priceDiff;
- }
- return a._auction.expires - b._auction.expires;
- });
- for (var i = 0; i < response.data.items.length; i++) {
- var player = response.data.items[i];
- var auction = player._auction;
- var buyNowPrice = auction.buyNowPrice;
- var tradeId = auction.tradeId;
- var tradeState = auction.tradeState;
- var expires = services.Localization.localizeAuctionTimeRemaining(auction.expires);
- if(!window.playersNotDesired.includes(auction.tradeId)){
- writeToDebugLog(player._staticData.firstName + ' ' + player._staticData.lastName + ' [' + auction.tradeId + '] [' + expires + '] ' + buyNowPrice);
- if (buyNowPrice <= window.buyPrice && !window.bids.includes(auction.tradeId) && --maxPurchases >= 0) {
- buyPlayer(player, buyNowPrice);
- if (!window.bids.includes(auction.tradeId)) {
- window.bids.push(auction.tradeId);
- if (window.bids.length > 300) {
- window.bids.shift();
- }
- }
- }else{
- window.playersNotDesired.push(auction.tradeId);
- if (window.playersNotDesired.length > 300) {
- window.playersNotDesired.shift();
- }
- }
- }
- };
- }else{
- window.deactivateAutoBuyer();
- window.telegram('Captcha Occured - Please Fix it !');
- }
- }));
- }
- window.updateFutMarket = function(sender, event, data) {
- if (!window.autoBuyerActive) {
- return;
- }
- writeToDebugLog('Search min price');
- services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
- type: PIN_PAGEVIEW_EVT_TYPE,
- pgid: "Transfer Market Search",
- });
- var searchCriteria = getAppMain().getRootViewController().getPresentedViewController().getCurrentViewController().getCurrentController()._viewmodel.searchCriteria;
- //searchCriteria.maxBid = window.getMaxSearchBid(300000, 800000);
- searchCriteria.minBid=window.getMinSearchBid();
- if(searchCriteria.level === "SP" && searchCriteria.minBuy === 0){
- searchCriteria.minBuy=10500;
- }
- searchCriteria.maxBuy=window.sellPrice
- services.Item.clearTransferMarketCache();
- services.Item.searchTransferMarket(searchCriteria, 1).observe(this, (function(sender, response) {
- if (response.success) {
- var explode = function(){
- services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
- type: PIN_PAGEVIEW_EVT_TYPE,
- pgid: "Transfer Market Results - List View",
- });
- if(response.data.items.length>0){
- services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
- type: PIN_PAGEVIEW_EVT_TYPE,
- pgid: "Item - Detail View",
- });
- }
- };
- setTimeout(explode, 1000)
- var nbResult = response.data.items.length;
- writeToDebugLog('Received ' + nbResult + ' items for search min bin');
- if(nbResult<2 && (window.previous==="UP" || window.previous==="")){
- window.previous="UP";
- window.sellPrice = window.tickUp(window.sellPrice)
- window.buyPrice = window.calculateBuyPrice(window.sellPrice * window.modifier)
- window.sellAfterTax= window.sellPrice - ((parseInt(window.sellPrice) / 100) * 5)
- }else if(nbResult > 5 && (window.previous==="DOWN" || window.previous==="")){
- window.previous="DOWN";
- window.sellPrice = window.tickDown(window.sellPrice)
- window.buyPrice = window.calculateBuyPrice(window.sellPrice * window.modifier)
- window.sellAfterTax= window.sellPrice - ((parseInt(window.sellPrice) / 100) * 5)
- }else{
- window.sellPrice = window.tickDown(window.sellPrice)
- window.sellAfterTax= window.sellPrice - ((parseInt(window.sellPrice) / 100) * 5)
- window.buyPrice = window.calculateBuyPrice(window.sellPrice * window.modifier)
- window.previous="";
- window.updatePrice = false;
- writeToDebugLog("---Nouveau prix de vente : "+window.sellPrice)
- writeToDebugLog("---Nouveau prix d'achat : "+window.buyPrice)
- }
- jQuery('#ab_sell_price').val(window.sellPrice);
- jQuery('#sell_after_tax').html(window.sellAfterTax.toLocaleString());
- jQuery('#benefits').html((window.sellAfterTax-window.buyPrice).toLocaleString());
- }else{
- window.deactivateAutoBuyer();
- window.telegram('Captcha Occured - Please Fix it !');
- }
- }));
- }
- window.buyPlayer = function(player, price) {
- services.Item.bid(player, price).observe(this, (function(sender, data){
- if (data.success) {
- var message = "";
- writeToLog("--------BUY----------")
- writeToLog(player._staticData.firstName + ' ' + player._staticData.lastName + ' [' + player._auction.tradeId + ']');
- var sellPrice = window.sellPrice;
- writeToLog(' -- Buy for: ' + price);
- message+=player._staticData.firstName + ' ' + player._staticData.lastName+ " -- Buy for : "+price
- if (sellPrice != '' && sellPrice !== 0) {
- writeToLog(' -- Selling for: ' + sellPrice);
- writeToLog(' -- Benefits : ' + parseInt(parseInt(jQuery('#ab_sell_price').val() - (parseInt(jQuery('#ab_sell_price').val()) / 20))-price));
- window.benefitTotal+=parseInt(parseInt(jQuery('#ab_sell_price').val() - (parseInt(jQuery('#ab_sell_price').val()) / 20))-price);
- message+=" -- Sell for :" +sellPrice;
- message+=" -- Benefits :" +parseInt(parseInt(jQuery('#ab_sell_price').val() - (parseInt(jQuery('#ab_sell_price').val()) / 20))-price);
- window.sellRequestTimeout = window.setTimeout(function() {
- services.Item.list(player, window.getSellBidPrice(sellPrice), sellPrice, 3600);
- }, window.getRandomWait());
- }
- window.telegram(message);
- } else {
- writeToLog("--------FAILED----------")
- writeToLog(player._staticData.firstName + ' ' + player._staticData.lastName + ' [' + player._auction.tradeId + '] ' + price);
- writeToLog(' -- Price : ' + price);
- }
- }));
- }
- window.getSellBidPrice = function(bin) {
- if (bin <= 1000) {
- return bin - 50;
- }
- if (bin > 1000 && bin <= 10000) {
- return bin - 100;
- }
- if (bin > 10000 && bin <= 50000) {
- return bin - 250;
- }
- if (bin > 50000 && bin <= 100000) {
- return bin - 500;
- }
- return bin - 1000;
- };
- window.updateTransferList = function() {
- services.Item.requestTransferItems().observe(this, function(t, response) {
- window.futStatistics.soldItems = response.data.items.filter(function(item) {
- return item.getAuctionData().isSold();
- }).length;
- window.futStatistics.unsoldItems = response.data.items.filter(function(item) {
- return !item.getAuctionData().isSold() && item.getAuctionData().isExpired();
- }).length;
- window.futStatistics.activeTransfers = response.data.items.filter(function(item) {
- return item.getAuctionData().isSelling();
- }).length;
- window.futStatistics.availableItems = response.data.items.filter(function(item) {
- return item.getAuctionData().isInactive();
- }).length;
- var minSoldCount = 50;
- if ($('#ab_min_delete_count').val() !== '') {
- minSoldCount = Math.max(1, parseInt($('#ab_min_delete_count').val()));
- }
- if (window.futStatistics.soldItems >= minSoldCount) {
- writeToLog(window.futStatistics.soldItems + " item(s) sold");
- window.clearSoldItems();
- }
- });
- }
- window.clearSoldItems = function() {
- services.Item.clearSoldItems().observe(this, function(t, response) {});
- }
- function getLeagueIdByAbbr(abbr) {
- var leagues = Object.values(repositories.TeamConfig._leagues._collection['11']._leagues._collection);
- var leagueId = 0;
- for(var i = 0; i < leagues.length; i++) {
- if (abbr === leagues[i].abbreviation) {
- leagueId = leagues[i].id;
- break;
- }
- }
- return leagueId;
- }
- window.calculateBuyPrice = function(price) {
- if (price <= 1000)
- {
- return Math.floor(price / 50.0) * 50;
- }
- else if (price <= 10000)
- {
- return Math.floor(price / 100.0) * 100;
- }
- else if (price <= 50000)
- {
- return Math.floor(price / 250.0) * 250;
- }
- else if (price <= 100000)
- {
- return Math.floor(price / 500.0) * 500;
- }
- else
- {
- return Math.floor(price / 1000.0) * 1000;
- }
- }
- window.tickUp = function(price) {
- if (price < 1000)
- {
- return price + 50;
- }
- else if (price < 10000)
- {
- return price + 100;
- }
- else if (price < 50000)
- {
- return price + 250;
- }
- else if (price < 100000)
- {
- return price + 500;
- }
- else
- {
- return price + 1000;
- }
- }
- window.tickDown = function(price) {
- if (price <= 1000)
- {
- return price - 50;
- }
- else if (price <= 10000)
- {
- return price - 100;
- }
- else if (price <= 50000)
- {
- return price - 250;
- }
- else if (price <= 100000)
- {
- return price - 500;
- }
- else
- {
- return price - 1000;
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement