-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea744fe
commit 4e16082
Showing
6 changed files
with
84 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
extension/scripts/features/item-market-fill-max/ttItemMarketFillMax.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.tt-show-fill-max [class*="rowWrapper__"] [class*="available__"] { | ||
align-items: flex-start; | ||
padding-top: 5px; | ||
} | ||
|
||
.tt-show-fill-max [class*="rowWrapper__"] [class*="available__"]::after { | ||
content: "Fill Max"; | ||
position: absolute; | ||
top: 20px; | ||
color: var(--tt-color-green); | ||
cursor: pointer; | ||
width: calc(100px - 2 * 7px); | ||
text-align: right; | ||
} | ||
|
||
body:not(.tt-mobile):not(.tt-tablet) .tt-show-fill-max [class*="rowWrapper__"] [class*="available__"]:hover::after { | ||
color: #fff; | ||
background-color: var(--tt-color-green); | ||
} |
49 changes: 49 additions & 0 deletions
49
extension/scripts/features/item-market-fill-max/ttItemMarketFillMax.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"use strict"; | ||
|
||
(async () => { | ||
const { mobile, tablet } = await checkDevice(); | ||
|
||
const feature = featureManager.registerFeature( | ||
"Item Market Fill Max", | ||
"item market", | ||
() => settings.pages.itemmarket.fillMax, | ||
addListener, | ||
addButton, | ||
removeButton, | ||
{ storage: ["settings.pages.itemmarket.fillMax"] }, | ||
() => { | ||
if (!hasAPIData()) return "No API access."; | ||
} | ||
); | ||
|
||
function addListener() { | ||
document.addEventListener("click", (event) => { | ||
if (!event.target.matches("[class*='rowWrapper__'] [class*='available__']")) return; | ||
|
||
if (!feature.enabled()) return; | ||
|
||
const listing = event.target.closest("li"); | ||
// The purchase amount input is not visible in mobiles and tablets until | ||
// the Buy icon is clicked. Hence exit early. | ||
if ((mobile || tablet) && !listing.children[0].matches("[class*='sellerRow__'][class*='expanded__']")) return; | ||
|
||
const quantityAvailable = listing.find("[class*='available__']").textContent.getNumber(); | ||
const moneyOnHand = document.find("#user-money").dataset.money.getNumber(); | ||
const itemPrice = listing.find("[class*='price__']").textContent.getNumber(); | ||
const purchasableQuantity = Math.min(quantityAvailable, Math.floor(moneyOnHand / itemPrice)); | ||
|
||
const quantityInput = listing.find(".input-money-group input:not([type])"); | ||
updateReactInput(quantityInput, purchasableQuantity); | ||
}); | ||
} | ||
|
||
async function addButton() { | ||
const itemMarketRoot = await requireElement("#item-market-root"); | ||
|
||
itemMarketRoot.classList.add("tt-show-fill-max"); | ||
} | ||
|
||
function removeButton() { | ||
document.findAll(".tt-show-fill-max").forEach((x) => x.classList.remove("tt-show-fill-max")); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters