Advertisement
Guest User

Untitled

a guest
Mar 18th, 2020
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.11 KB | None | 0 0
  1. // ==UserScript==
  2. // @name FUT20 Autobuyer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @updateURL https://github.com/Vivalemuc/futtamper/blob/master/fut_autobuyer.js
  6. // @description try to take over the world!
  7. // @author Vivalemuc
  8. // @match https://www.easports.com/uk/fifa/ultimate-team/web-app/*
  9. // @match https://www.easports.com/fifa/ultimate-team/web-app/*
  10. // @grant none
  11. // @require http://code.jquery.com/jquery-3.4.1.min.js
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. window.getMaxSearchBid = function(min, max) {
  17. return Math.round((Math.random() * (max - min) + min) / 1000) * 1000;
  18. };
  19.  
  20. window.getMinSearchBid = function() {
  21. var wait = [100, 800];
  22. if (jQuery('#ab_min_bid_range').val() !== '') {
  23. wait = jQuery('#ab_min_bid_range').val().split('-');
  24. }
  25. var bid = Math.round((Math.random() * (wait[1] - wait[0]) + wait[0]) / 100) * 100;
  26. return bid;
  27. };
  28.  
  29. window.searchCount = 0;
  30.  
  31. window.initStatistics = function() {
  32. window.futStatistics = {
  33. soldItems: '-',
  34. unsoldItems: '-',
  35. activeTransfers: '-',
  36. availableItems: '-',
  37. coins: '-',
  38. };
  39.  
  40. window.timers = {
  41. updatePrice: window.createTimeout(0, 0),
  42. search: window.createTimeout(0, 0),
  43. coins: window.createTimeout(0, 0),
  44. transferList: window.createTimeout(0, 0),
  45. };
  46. };
  47.  
  48. window.bids = [];
  49. window.playersNotDesired = [];
  50.  
  51. window.createTimeout = function(time, interval) {
  52. return {
  53. start: time,
  54. finish: time + interval,
  55. };
  56. };
  57.  
  58. window.processor = window.setInterval(function() {
  59. if (window.autoBuyerActive) {
  60. var time = (new Date()).getTime();
  61.  
  62. if (window.timers.search.finish == 0 || window.timers.search.finish <= time) {
  63. if(window.updatePrice){
  64. window.updateFutMarket(null, null, null);
  65. window.timers.search = window.createTimeout(time, window.getRandomWaitForUpdatePrice());
  66. }else{
  67. window.searchFutMarket(null, null, null);
  68. window.timers.search = window.createTimeout(time, window.getRandomWait());
  69. }
  70. }
  71.  
  72. if (window.timers.coins.finish == 0 || window.timers.coins.finish <= time) {
  73. window.futStatistics.coins = services.User.getUser().coins.amount.toLocaleString();
  74.  
  75. window.timers.coins = window.createTimeout(time, 2500);
  76. }
  77.  
  78. if (window.timers.transferList.finish == 0 || window.timers.transferList.finish <= time) {
  79. window.updateTransferList();
  80.  
  81. window.timers.transferList = window.createTimeout(time, 30000);
  82. }
  83. } else {
  84. window.initStatistics();
  85. }
  86.  
  87. window.updateStatistics();
  88. }, 500);
  89.  
  90. window.searchFutMarket = function(sender, event, data) {
  91.  
  92. if (!window.autoBuyerActive) {
  93. return;
  94. }
  95.  
  96. services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
  97. type: PIN_PAGEVIEW_EVT_TYPE,
  98. pgid: "Transfer Market Search",
  99. });
  100.  
  101. var searchCriteria = getAppMain().getRootViewController().getPresentedViewController().getCurrentViewController().getCurrentController()._viewmodel.searchCriteria;
  102.  
  103. searchCriteria.maxBid = window.getMaxSearchBid(300000, 800000);
  104.  
  105. searchCriteria.minBid=window.getMinSearchBid();
  106.  
  107. if(searchCriteria.level === "SP" && searchCriteria.minBuy === 0){
  108. searchCriteria.minBuy=10500;
  109. }
  110. if(window.modifier<=1.0){
  111. searchCriteria.maxBuy=window.sellPrice
  112. }
  113.  
  114. services.Item.clearTransferMarketCache();
  115.  
  116. services.Item.searchTransferMarket(searchCriteria, 1).observe(this, (function(sender, response) {
  117. if (response.success) {
  118. var explode = function(){
  119. services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
  120. type: PIN_PAGEVIEW_EVT_TYPE,
  121. pgid: "Transfer Market Results - List View",
  122. });
  123. if(response.data.items.length>0){
  124. services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
  125. type: PIN_PAGEVIEW_EVT_TYPE,
  126. pgid: "Item - Detail View",
  127. });
  128. }
  129. };
  130.  
  131. setTimeout(explode, 1000);
  132.  
  133.  
  134. writeToDebugLog('Received ' + response.data.items.length + ' items');
  135.  
  136. var maxPurchases = 3;
  137. if ($('#ab_max_purchases').val() !== '') {
  138. maxPurchases = Math.max(1, parseInt($('#ab_max_purchases').val()));
  139. }
  140.  
  141. response.data.items.sort(function(a, b) {
  142. var priceDiff = a._auction.buyNowPrice - b._auction.buyNowPrice;
  143.  
  144. if (priceDiff != 0) {
  145. return priceDiff;
  146. }
  147.  
  148. return a._auction.expires - b._auction.expires;
  149. });
  150.  
  151. for (var i = 0; i < response.data.items.length; i++) {
  152. var player = response.data.items[i];
  153. var auction = player._auction;
  154.  
  155. var buyNowPrice = auction.buyNowPrice;
  156. var tradeId = auction.tradeId;
  157. var tradeState = auction.tradeState;
  158.  
  159. var expires = services.Localization.localizeAuctionTimeRemaining(auction.expires);
  160. if(!window.playersNotDesired.includes(auction.tradeId)){
  161. writeToDebugLog(player._staticData.firstName + ' ' + player._staticData.lastName + ' [' + auction.tradeId + '] [' + expires + '] ' + buyNowPrice);
  162.  
  163. if (buyNowPrice <= window.buyPrice && !window.bids.includes(auction.tradeId) && --maxPurchases >= 0) {
  164. buyPlayer(player, buyNowPrice);
  165.  
  166. if (!window.bids.includes(auction.tradeId)) {
  167. window.bids.push(auction.tradeId);
  168.  
  169. if (window.bids.length > 300) {
  170. window.bids.shift();
  171. }
  172. }
  173. }else{
  174. window.playersNotDesired.push(auction.tradeId);
  175.  
  176. if (window.playersNotDesired.length > 300) {
  177. window.playersNotDesired.shift();
  178. }
  179. }
  180. }
  181. };
  182. }else{
  183. window.deactivateAutoBuyer();
  184. window.telegram('Captcha Occured - Please Fix it !');
  185. }
  186. }));
  187. }
  188.  
  189.  
  190. window.updateFutMarket = function(sender, event, data) {
  191.  
  192. if (!window.autoBuyerActive) {
  193. return;
  194. }
  195. writeToDebugLog('Search min price');
  196.  
  197. services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
  198. type: PIN_PAGEVIEW_EVT_TYPE,
  199. pgid: "Transfer Market Search",
  200. });
  201.  
  202. var searchCriteria = getAppMain().getRootViewController().getPresentedViewController().getCurrentViewController().getCurrentController()._viewmodel.searchCriteria;
  203.  
  204. //searchCriteria.maxBid = window.getMaxSearchBid(300000, 800000);
  205.  
  206. searchCriteria.minBid=window.getMinSearchBid();
  207.  
  208. if(searchCriteria.level === "SP" && searchCriteria.minBuy === 0){
  209. searchCriteria.minBuy=10500;
  210. }
  211.  
  212. searchCriteria.maxBuy=window.sellPrice
  213.  
  214. services.Item.clearTransferMarketCache();
  215.  
  216. services.Item.searchTransferMarket(searchCriteria, 1).observe(this, (function(sender, response) {
  217. if (response.success) {
  218. var explode = function(){
  219. services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
  220. type: PIN_PAGEVIEW_EVT_TYPE,
  221. pgid: "Transfer Market Results - List View",
  222. });
  223. if(response.data.items.length>0){
  224. services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, {
  225. type: PIN_PAGEVIEW_EVT_TYPE,
  226. pgid: "Item - Detail View",
  227. });
  228. }
  229. };
  230.  
  231. setTimeout(explode, 1000)
  232. var nbResult = response.data.items.length;
  233.  
  234. writeToDebugLog('Received ' + nbResult + ' items for search min bin');
  235. if(nbResult<2 && (window.previous==="UP" || window.previous==="")){
  236. window.previous="UP";
  237. window.sellPrice = window.tickUp(window.sellPrice)
  238. window.buyPrice = window.calculateBuyPrice(window.sellPrice * window.modifier)
  239. window.sellAfterTax= window.sellPrice - ((parseInt(window.sellPrice) / 100) * 5)
  240.  
  241. }else if(nbResult > 5 && (window.previous==="DOWN" || window.previous==="")){
  242. window.previous="DOWN";
  243. window.sellPrice = window.tickDown(window.sellPrice)
  244. window.buyPrice = window.calculateBuyPrice(window.sellPrice * window.modifier)
  245. window.sellAfterTax= window.sellPrice - ((parseInt(window.sellPrice) / 100) * 5)
  246. }else{
  247. window.sellPrice = window.tickDown(window.sellPrice)
  248. window.sellAfterTax= window.sellPrice - ((parseInt(window.sellPrice) / 100) * 5)
  249. window.buyPrice = window.calculateBuyPrice(window.sellPrice * window.modifier)
  250. window.previous="";
  251. window.updatePrice = false;
  252. writeToDebugLog("---Nouveau prix de vente : "+window.sellPrice)
  253. writeToDebugLog("---Nouveau prix d'achat : "+window.buyPrice)
  254. }
  255. jQuery('#ab_sell_price').val(window.sellPrice);
  256. jQuery('#sell_after_tax').html(window.sellAfterTax.toLocaleString());
  257. jQuery('#benefits').html((window.sellAfterTax-window.buyPrice).toLocaleString());
  258. }else{
  259. window.deactivateAutoBuyer();
  260. window.telegram('Captcha Occured - Please Fix it !');
  261. }
  262. }));
  263. }
  264.  
  265. window.buyPlayer = function(player, price) {
  266. services.Item.bid(player, price).observe(this, (function(sender, data){
  267. if (data.success) {
  268. var message = "";
  269. writeToLog("--------BUY----------")
  270. writeToLog(player._staticData.firstName + ' ' + player._staticData.lastName + ' [' + player._auction.tradeId + ']');
  271. var sellPrice = window.sellPrice;
  272. writeToLog(' -- Buy for: ' + price);
  273. message+=player._staticData.firstName + ' ' + player._staticData.lastName+ " -- Buy for : "+price
  274. if (sellPrice != '' && sellPrice !== 0) {
  275. writeToLog(' -- Selling for: ' + sellPrice);
  276. writeToLog(' -- Benefits : ' + parseInt(parseInt(jQuery('#ab_sell_price').val() - (parseInt(jQuery('#ab_sell_price').val()) / 20))-price));
  277. window.benefitTotal+=parseInt(parseInt(jQuery('#ab_sell_price').val() - (parseInt(jQuery('#ab_sell_price').val()) / 20))-price);
  278. message+=" -- Sell for :" +sellPrice;
  279. message+=" -- Benefits :" +parseInt(parseInt(jQuery('#ab_sell_price').val() - (parseInt(jQuery('#ab_sell_price').val()) / 20))-price);
  280.  
  281. window.sellRequestTimeout = window.setTimeout(function() {
  282. services.Item.list(player, window.getSellBidPrice(sellPrice), sellPrice, 3600);
  283. }, window.getRandomWait());
  284. }
  285. window.telegram(message);
  286. } else {
  287. writeToLog("--------FAILED----------")
  288. writeToLog(player._staticData.firstName + ' ' + player._staticData.lastName + ' [' + player._auction.tradeId + '] ' + price);
  289. writeToLog(' -- Price : ' + price);
  290. }
  291. }));
  292. }
  293.  
  294. window.getSellBidPrice = function(bin) {
  295. if (bin <= 1000) {
  296. return bin - 50;
  297. }
  298.  
  299. if (bin > 1000 && bin <= 10000) {
  300. return bin - 100;
  301. }
  302.  
  303. if (bin > 10000 && bin <= 50000) {
  304. return bin - 250;
  305. }
  306.  
  307. if (bin > 50000 && bin <= 100000) {
  308. return bin - 500;
  309. }
  310.  
  311. return bin - 1000;
  312. };
  313.  
  314. window.updateTransferList = function() {
  315. services.Item.requestTransferItems().observe(this, function(t, response) {
  316. window.futStatistics.soldItems = response.data.items.filter(function(item) {
  317. return item.getAuctionData().isSold();
  318. }).length;
  319.  
  320. window.futStatistics.unsoldItems = response.data.items.filter(function(item) {
  321. return !item.getAuctionData().isSold() && item.getAuctionData().isExpired();
  322. }).length;
  323.  
  324. window.futStatistics.activeTransfers = response.data.items.filter(function(item) {
  325. return item.getAuctionData().isSelling();
  326. }).length;
  327.  
  328. window.futStatistics.availableItems = response.data.items.filter(function(item) {
  329. return item.getAuctionData().isInactive();
  330. }).length;
  331.  
  332. var minSoldCount = 50;
  333. if ($('#ab_min_delete_count').val() !== '') {
  334. minSoldCount = Math.max(1, parseInt($('#ab_min_delete_count').val()));
  335. }
  336.  
  337. if (window.futStatistics.soldItems >= minSoldCount) {
  338. writeToLog(window.futStatistics.soldItems + " item(s) sold");
  339. window.clearSoldItems();
  340. }
  341. });
  342. }
  343.  
  344. window.clearSoldItems = function() {
  345. services.Item.clearSoldItems().observe(this, function(t, response) {});
  346. }
  347.  
  348. function getLeagueIdByAbbr(abbr) {
  349. var leagues = Object.values(repositories.TeamConfig._leagues._collection['11']._leagues._collection);
  350. var leagueId = 0;
  351. for(var i = 0; i < leagues.length; i++) {
  352. if (abbr === leagues[i].abbreviation) {
  353. leagueId = leagues[i].id;
  354. break;
  355. }
  356. }
  357.  
  358. return leagueId;
  359. }
  360.  
  361. window.calculateBuyPrice = function(price) {
  362. if (price <= 1000)
  363. {
  364. return Math.floor(price / 50.0) * 50;
  365. }
  366. else if (price <= 10000)
  367. {
  368. return Math.floor(price / 100.0) * 100;
  369. }
  370. else if (price <= 50000)
  371. {
  372. return Math.floor(price / 250.0) * 250;
  373. }
  374. else if (price <= 100000)
  375. {
  376. return Math.floor(price / 500.0) * 500;
  377. }
  378. else
  379. {
  380. return Math.floor(price / 1000.0) * 1000;
  381. }
  382. }
  383.  
  384. window.tickUp = function(price) {
  385. if (price < 1000)
  386. {
  387. return price + 50;
  388. }
  389. else if (price < 10000)
  390. {
  391. return price + 100;
  392. }
  393. else if (price < 50000)
  394. {
  395. return price + 250;
  396. }
  397. else if (price < 100000)
  398. {
  399. return price + 500;
  400. }
  401. else
  402. {
  403. return price + 1000;
  404. }
  405. }
  406.  
  407. window.tickDown = function(price) {
  408. if (price <= 1000)
  409. {
  410. return price - 50;
  411. }
  412. else if (price <= 10000)
  413. {
  414. return price - 100;
  415. }
  416. else if (price <= 50000)
  417. {
  418. return price - 250;
  419. }
  420. else if (price <= 100000)
  421. {
  422. return price - 500;
  423. }
  424. else
  425. {
  426. return price - 1000;
  427. }
  428. }
  429.  
  430. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement