diff --git a/app/index.js b/app/index.js index 8c88e2f..6b27f78 100644 --- a/app/index.js +++ b/app/index.js @@ -7,15 +7,16 @@ import { analytics, Settings, Queue } from './core'; import { Logger } from '../fut'; /* -import { CardInfoSettings, RefreshListSettings, RemoveSoldAuctionsSettings, RelistAuctionsSettings, - MinBinSettings, ListSizeSettings, -} from './transferlist'; */ +import { + MinBinSettings, +} from './transferlist'; + import { FutbinSettings, } from './futbin'; @@ -55,7 +56,7 @@ services.Authentication._oAuthentication.observe( // settings.registerEntry(new RefreshListSettings()); // settings.registerEntry(new RemoveSoldAuctionsSettings()); // settings.registerEntry(new RelistAuctionsSettings()); - // settings.registerEntry(new MinBinSettings()); + settings.registerEntry(new MinBinSettings()); // settings.registerEntry(new CardInfoSettings()); // settings.registerEntry(new ListSizeSettings()); diff --git a/app/transferlist/min-bin.js b/app/transferlist/min-bin.js index 4caadb2..593c59d 100644 --- a/app/transferlist/min-bin.js +++ b/app/transferlist/min-bin.js @@ -1,5 +1,4 @@ /* globals -gNavManager window $ document */ import { BaseScript, SettingsEntry } from '../core'; @@ -52,83 +51,85 @@ class MinBin extends BaseScript { mutationRecords.forEach(function (mutation) { if ($(mutation.target).hasClass('DetailView') && $(mutation.target) .find('.DetailPanel') && mutation.addedNodes.length > 0) { - if ($(mutation.target).find('#searchMinBin').length === 0) { - let selectedItem = this._getSelectedItem(); + const searchMinBin = $(mutation.target).find('#searchMinBin'); + searchMinBin.remove(); - if (selectedItem == null || selectedItem.resourceId === 0) { - return; + let selectedItem = this._getSelectedItem(); + + if (selectedItem == null || selectedItem.resourceId === 0) { + return; + } + const knownPlayerPrice = this._playerPrices + .find(p => p.resourceId === selectedItem.resourceId); + let price = ''; + if (knownPlayerPrice != null) { + price = `(${knownPlayerPrice.minimumBin})`; + + this._updateListPrice(knownPlayerPrice.minimumBin); + } + $(mutation.target).find('.DetailPanel > .ut-button-group').prepend(``); + + $('#searchMinBin').bind('click', async () => { + const btn = $('#searchMinBin'); + btn.find('.btn-text').html('Searching minimum BIN...'); + const settings = this.getSettings(); + const minimumBin = await new TransferMarket().searchMinBuy(selectedItem, parseInt(settings['mean-count'], 10)); + const playerPrice = this._playerPrices.find(p => p.resourceId === btn.data('resource-id')); + if (playerPrice != null) { + this._playerPrices.splice(this._playerPrices.indexOf(playerPrice), 1); } - const knownPlayerPrice = this._playerPrices - .find(p => p.resourceId === selectedItem.resourceId); - let price = ''; - if (knownPlayerPrice != null) { - price = `(${knownPlayerPrice.minimumBin})`; + this._playerPrices.push({ + resourceId: btn.data('resource-id'), + minimumBin, + }); - this._updateListPrice(knownPlayerPrice.minimumBin); + selectedItem = this._getSelectedItem(); + + if (btn.data('resource-id') === selectedItem.resourceId) { + btn.find('.btn-text').html(`Search minimum BIN (${minimumBin})`); + + this._updateListPrice(minimumBin); } - $(mutation.target).find('.DetailPanel ul').prepend(``); - - $('#searchMinBin').bind('click', async () => { - const btn = $('#searchMinBin'); - btn.find('.btn-text').html('Searching minimum BIN...'); - const settings = this.getSettings(); - const minimumBin = await new TransferMarket().searchMinBuy(selectedItem, parseInt(settings['mean-count'], 10)); - const playerPrice = this._playerPrices.find(p => p.resourceId === btn.data('resource-id')); - if (playerPrice != null) { - this._playerPrices.splice(this._playerPrices.indexOf(playerPrice), 1); - } - this._playerPrices.push({ - resourceId: btn.data('resource-id'), - minimumBin, - }); - - selectedItem = this._getSelectedItem(); - - if (btn.data('resource-id') === selectedItem.resourceId) { - btn.find('.btn-text').html(`Search minimum BIN (${minimumBin})`); - - this._updateListPrice(minimumBin); - } - - GM_notification({ - text: `Minimum BIN found for ${selectedItem._staticData.name} is ${minimumBin}`, - title: 'FUT 18 Web App', - timeout: 5000, - onclick: () => window.focus(), - }); + + GM_notification({ + text: `Minimum BIN found for ${selectedItem._staticData.name} is ${minimumBin}`, + title: 'FUT 19 Web App', + timeout: 5000, + onclick: () => window.focus(), }); - } + }); } }, this); } _updateListPrice(minimumBin) { const settings = this.getSettings(); - if (settings['adjust-list-price'] && - gNavManager.getCurrentScreenController()._controller._rightController - ._currentController._quickListPanel) { - const quicklistpanelController = gNavManager.getCurrentScreenController() - ._controller._rightController - ._currentController._quickListPanel; - const quicklistpanel = quicklistpanelController._view; + const quicklistPanel = getAppMain().getRootViewController() + .getPresentedViewController() + .getCurrentViewController() + .getCurrentController() + ._rightController._currentController._quickListPanel; + + if (settings['adjust-list-price'] && quicklistPanel) { + const quicklistpanelView = quicklistPanel._view; const listPrice = priceTiers.determineListPrice( minimumBin * (settings['start-price-percentage'] / 100), minimumBin * (settings['buy-now-price-percentage'] / 100), ); - if (quicklistpanelController._item) { + if (quicklistPanel._item) { // sets the values when the quicklistpanel hasn't been initialized - const auction = quicklistpanelController._item._auction; + const auction = quicklistPanel._item._auction; if (auction.tradeState !== 'active') { auction.startingBid = listPrice.start; auction.buyNowPrice = listPrice.buyNow; - quicklistpanelController._item.setAuctionData(auction); + quicklistPanel._item.setAuctionData(auction); } } - const bidSpinner = quicklistpanel._bidNumericStepper; - const buySpinner = quicklistpanel._buyNowNumericStepper; + const bidSpinner = quicklistpanelView._bidNumericStepper; + const buySpinner = quicklistpanelView._buyNowNumericStepper; bidSpinner.value = listPrice.start; buySpinner.value = listPrice.buyNow; } @@ -136,13 +137,20 @@ class MinBin extends BaseScript { /* eslint-disable class-methods-use-this */ _getSelectedItem() { - if (gNavManager.getCurrentScreenController()._controller._listController) { - return gNavManager.getCurrentScreenController()._controller._listController - .getIterator().current(); + const listController = getAppMain().getRootViewController() + .getPresentedViewController() + .getCurrentViewController() + .getCurrentController()._listController; + if (listController) { + return listController.getIterator().current(); } - if (gNavManager.getCurrentScreenController()._controller._rightController._currentController) { - const current = gNavManager.getCurrentScreenController()._controller._rightController + const detailController = getAppMain().getRootViewController() + .getPresentedViewController() + .getCurrentViewController() + .getCurrentController()._rightController; + if (detailController) { + const current = detailController ._currentController._viewmodel.current(); return current._item ? current._item : current; diff --git a/fut/pinEvent.js b/fut/pinEvent.js index 1cf6ac0..1768e75 100644 --- a/fut/pinEvent.js +++ b/fut/pinEvent.js @@ -1,13 +1,13 @@ -/* globals gPinManager PinManager utils enums */ +/* globals PIN_PAGEVIEW_EVT_TYPE services enums */ export class PinEvent { static sendPageView(pageId, delay = 2000) { return new Promise(resolve => setTimeout(() => { - gPinManager.trigger(utils.PinFactory.createEvent(enums.PIN.EVENT.PAGE_VIEW, { - type: PinManager.PAGEVIEW_EVT_TYPE, + services.PIN.sendData(enums.PIN.EVENT.PAGE_VIEW, { + type: PIN_PAGEVIEW_EVT_TYPE, pgid: pageId, - })); + }); resolve(); }, delay)); } diff --git a/fut/priceTiers.js b/fut/priceTiers.js index 2001eb5..9bd7913 100644 --- a/fut/priceTiers.js +++ b/fut/priceTiers.js @@ -1,7 +1,7 @@ -/* global utils components */ +/* global utils views */ export default { roundValueToNearestPriceTiers(value) { - const tier = utils.JS.find(components.NumericInput.PRICE_TIERS, i => value > i.min); + const tier = utils.JS.find(views.controls.CurrencyInput.PRICE_TIERS, i => value > i.min); const diff = value % tier.inc; @@ -14,7 +14,7 @@ export default { }, roundDownToNearestPriceTiers(value) { - const tier = utils.JS.find(components.NumericInput.PRICE_TIERS, i => value > i.min); + const tier = utils.JS.find(views.controls.CurrencyInput.PRICE_TIERS, i => value > i.min); const diff = value % tier.inc; @@ -25,7 +25,7 @@ export default { }, determineListPrice(start, buyNow) { - const tier = utils.JS.find(components.NumericInput.PRICE_TIERS, i => buyNow > i.min); + const tier = utils.JS.find(views.controls.CurrencyInput.PRICE_TIERS, i => buyNow > i.min); const startPrice = this.roundValueToNearestPriceTiers(start); let buyNowPrice = this.roundValueToNearestPriceTiers(buyNow); diff --git a/fut/transferMarket.js b/fut/transferMarket.js index fec4c86..478811a 100644 --- a/fut/transferMarket.js +++ b/fut/transferMarket.js @@ -123,8 +123,9 @@ export class TransferMarket { async _findLowUp(item, itemsForMean) { const searchCriteria = this._defineSearchCriteria(item, 200); await PinEvent.sendPageView('Transfer Market Search'); - await utils.sleep(5000); + await utils.sleep(3000); await PinEvent.sendPageView('Transfer Market Results - List View', 0); + await PinEvent.sendPageView('Item - Detail View', 0); const items = await this._find(searchCriteria); if (items.length > itemsForMean) { // we find more than X listed at this price, so it must be low value @@ -142,7 +143,9 @@ export class TransferMarket { for (let minBuyFound = false; minBuyFound === false;) { /* eslint-disable no-await-in-loop */ await PinEvent.sendPageView('Transfer Market Search'); + await utils.sleep(800); await PinEvent.sendPageView('Transfer Market Results - List View', 0); + await PinEvent.sendPageView('Item - Detail View', 0); const items = await this._find(searchCriteria); /* eslint-enable no-await-in-loop */ if (items.length > 0) { @@ -195,9 +198,9 @@ export class TransferMarket { // if it is TOTW or other special, set it to TOTW. See enums.ItemRareType. // Can only search for "Specials", not more specific on Rare Type - if (item.rareflag >= enums.ItemRareType.TOTW) { + if (item.rareflag >= 3) { // 3 = TOTW searchCriteria.level = factories.DataProvider.getItemLevelDP(true) - .filter(d => d.id === enums.ItemRareType.TOTW)[0].value; + .filter(d => d.id === 3)[0].value; } searchCriteria.category = enums.SearchCategory.ANY;