Skip to content

Commit

Permalink
Fill Max for Item Market 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sashank999 committed Jan 26, 2025
1 parent ea744fe commit 4e16082
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
5 changes: 4 additions & 1 deletion extension/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"title": "Beta",
"date": false,
"logs": {
"features": [{ "message": "Sidebar timer for OC 2.", "contributor": "DeKleineKobini" }],
"features": [
{ "message": "Sidebar timer for OC 2.", "contributor": "DeKleineKobini" },
{ "message": "Fill Max for Item Market 2.0.", "contributor": "TheFoxMan" }
],
"fixes": [],
"changes": [
{ "message": "Disable OC1 timer when detecting OC 2 data.", "contributor": "DeKleineKobini" },
Expand Down
9 changes: 7 additions & 2 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,16 @@
},
{
"matches": ["https://www.torn.com/page.php?sid=ItemMarket*"],
"css": ["scripts/features/drug-details/ttDrugDetails.css", "scripts/features/highlight-cheap-items/ttHighlightCheapItems.css"],
"css": [
"scripts/features/drug-details/ttDrugDetails.css",
"scripts/features/highlight-cheap-items/ttHighlightCheapItems.css",
"scripts/features/item-market-fill-max/ttItemMarketFillMax.css"
],
"js": [
"scripts/content/itemmarket/ttItemMarket.js",
"scripts/features/drug-details/ttDrugDetails.js",
"scripts/features/highlight-cheap-items/ttHighlightCheapItems.js"
"scripts/features/highlight-cheap-items/ttHighlightCheapItems.js",
"scripts/features/item-market-fill-max/ttItemMarketFillMax.js"
],
"run_at": "document_end"
},
Expand Down
4 changes: 4 additions & 0 deletions extension/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,10 @@ <h2>
<input id="itemmarket-leftBar" type="checkbox" />
<label for="itemmarket-leftBar">Move the market bar to the left.</label>
</div>
<div class="option">
<input id="itemmarket-fillMax" type="checkbox" />
<label for="itemmarket-fillMax">Show fill max button to fill input box with maximum purchasable quantity.</label>
</div>
</section>
<section name="bounties">
<div class="header">Bounties</div>
Expand Down
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);
}
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"));
}
})();
1 change: 1 addition & 0 deletions extension/scripts/global/globalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ const DEFAULT_STORAGE = {
itemmarket: {
highlightCheapItems: new DefaultSetting({ type: "number|empty", defaultValue: "" }),
leftBar: new DefaultSetting({ type: "boolean", defaultValue: false }),
fillMax: new DefaultSetting({ type: "boolean", defaultValue: true }),
},
competition: {
filter: new DefaultSetting({ type: "boolean", defaultValue: true }),
Expand Down

0 comments on commit 4e16082

Please sign in to comment.