|
1 |
| -"use strict"; |
2 |
| - |
3 |
| -(async () => { |
4 |
| - const { mobile, tablet } = await checkDevice(); |
5 |
| - |
6 |
| - const feature = featureManager.registerFeature( |
7 |
| - "Item Market Fill Max", |
8 |
| - "item market", |
9 |
| - () => settings.pages.itemmarket.fillMax, |
10 |
| - addListener, |
11 |
| - addButton, |
12 |
| - removeButton, |
13 |
| - { storage: ["settings.pages.itemmarket.fillMax"] }, |
14 |
| - () => { |
15 |
| - if (!hasAPIData()) return "No API access."; |
16 |
| - } |
17 |
| - ); |
18 |
| - |
19 |
| - function addListener() { |
20 |
| - document.addEventListener("click", (event) => { |
21 |
| - if (!event.target.matches("[class*='rowWrapper__'] [class*='available__']")) return; |
22 |
| - |
23 |
| - if (!feature.enabled()) return; |
24 |
| - |
25 |
| - const listing = event.target.closest("li"); |
26 |
| - // The purchase amount input is not visible in mobiles and tablets until |
27 |
| - // the Buy icon is clicked. Hence exit early. |
28 |
| - if ((mobile || tablet) && !listing.children[0].matches("[class*='sellerRow__'][class*='expanded__']")) return; |
29 |
| - |
30 |
| - const quantityAvailable = listing.find("[class*='available__']").textContent.getNumber(); |
31 |
| - const moneyOnHand = document.find("#user-money").dataset.money.getNumber(); |
32 |
| - const itemPrice = listing.find("[class*='price__']").textContent.getNumber(); |
33 |
| - const purchasableQuantity = Math.min(quantityAvailable, Math.floor(moneyOnHand / itemPrice)); |
34 |
| - |
35 |
| - const quantityInput = listing.find(".input-money-group input:not([type])"); |
36 |
| - updateReactInput(quantityInput, purchasableQuantity); |
37 |
| - }); |
38 |
| - } |
39 |
| - |
40 |
| - async function addButton() { |
41 |
| - const itemMarketRoot = await requireElement("#item-market-root"); |
42 |
| - |
43 |
| - itemMarketRoot.classList.add("tt-show-fill-max"); |
44 |
| - } |
45 |
| - |
46 |
| - function removeButton() { |
47 |
| - document.findAll(".tt-show-fill-max").forEach((x) => x.classList.remove("tt-show-fill-max")); |
48 |
| - } |
49 |
| -})(); |
| 1 | +"use strict"; |
| 2 | + |
| 3 | +(async () => { |
| 4 | + const { mobile, tablet } = await checkDevice(); |
| 5 | + |
| 6 | + const feature = featureManager.registerFeature( |
| 7 | + "Item Market Fill Max", |
| 8 | + "item market", |
| 9 | + () => settings.pages.itemmarket.fillMax, |
| 10 | + addListener, |
| 11 | + addButton, |
| 12 | + removeButton, |
| 13 | + { storage: ["settings.pages.itemmarket.fillMax"] }, |
| 14 | + () => { |
| 15 | + if (!hasAPIData()) return "No API access."; |
| 16 | + } |
| 17 | + ); |
| 18 | + |
| 19 | + function addListener() { |
| 20 | + document.addEventListener("click", (event) => { |
| 21 | + if (!event.target.matches("[class*='rowWrapper__'] [class*='available__']")) return; |
| 22 | + |
| 23 | + if (!feature.enabled()) return; |
| 24 | + |
| 25 | + const listing = event.target.closest("li"); |
| 26 | + // The purchase amount input is not visible in mobiles and tablets until |
| 27 | + // the Buy icon is clicked. Hence exit early. |
| 28 | + if ((mobile || tablet) && !listing.children[0].matches("[class*='sellerRow__'][class*='expanded__']")) return; |
| 29 | + |
| 30 | + const quantityAvailable = listing.find("[class*='available__']").textContent.getNumber(); |
| 31 | + const moneyOnHand = document.find("#user-money").dataset.money.getNumber(); |
| 32 | + const itemPrice = listing.find("[class*='price__']").textContent.getNumber(); |
| 33 | + const purchasableQuantity = Math.min(quantityAvailable, Math.floor(moneyOnHand / itemPrice)); |
| 34 | + |
| 35 | + const quantityInput = listing.find(".input-money-group input:not([type])"); |
| 36 | + updateReactInput(quantityInput, purchasableQuantity); |
| 37 | + }); |
| 38 | + } |
| 39 | + |
| 40 | + async function addButton() { |
| 41 | + const itemMarketRoot = await requireElement("#item-market-root"); |
| 42 | + |
| 43 | + itemMarketRoot.classList.add("tt-show-fill-max"); |
| 44 | + } |
| 45 | + |
| 46 | + function removeButton() { |
| 47 | + document.findAll(".tt-show-fill-max").forEach((x) => x.classList.remove("tt-show-fill-max")); |
| 48 | + } |
| 49 | +})(); |
0 commit comments