Skip to content

Commit 4e16082

Browse files
committed
Fill Max for Item Market 2.0.
1 parent ea744fe commit 4e16082

File tree

6 files changed

+84
-3
lines changed

6 files changed

+84
-3
lines changed

extension/changelog.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"title": "Beta",
55
"date": false,
66
"logs": {
7-
"features": [{ "message": "Sidebar timer for OC 2.", "contributor": "DeKleineKobini" }],
7+
"features": [
8+
{ "message": "Sidebar timer for OC 2.", "contributor": "DeKleineKobini" },
9+
{ "message": "Fill Max for Item Market 2.0.", "contributor": "TheFoxMan" }
10+
],
811
"fixes": [],
912
"changes": [
1013
{ "message": "Disable OC1 timer when detecting OC 2 data.", "contributor": "DeKleineKobini" },

extension/manifest.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,16 @@
430430
},
431431
{
432432
"matches": ["https://www.torn.com/page.php?sid=ItemMarket*"],
433-
"css": ["scripts/features/drug-details/ttDrugDetails.css", "scripts/features/highlight-cheap-items/ttHighlightCheapItems.css"],
433+
"css": [
434+
"scripts/features/drug-details/ttDrugDetails.css",
435+
"scripts/features/highlight-cheap-items/ttHighlightCheapItems.css",
436+
"scripts/features/item-market-fill-max/ttItemMarketFillMax.css"
437+
],
434438
"js": [
435439
"scripts/content/itemmarket/ttItemMarket.js",
436440
"scripts/features/drug-details/ttDrugDetails.js",
437-
"scripts/features/highlight-cheap-items/ttHighlightCheapItems.js"
441+
"scripts/features/highlight-cheap-items/ttHighlightCheapItems.js",
442+
"scripts/features/item-market-fill-max/ttItemMarketFillMax.js"
438443
],
439444
"run_at": "document_end"
440445
},

extension/pages/settings/settings.html

+4
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,10 @@ <h2>
16041604
<input id="itemmarket-leftBar" type="checkbox" />
16051605
<label for="itemmarket-leftBar">Move the market bar to the left.</label>
16061606
</div>
1607+
<div class="option">
1608+
<input id="itemmarket-fillMax" type="checkbox" />
1609+
<label for="itemmarket-fillMax">Show fill max button to fill input box with maximum purchasable quantity.</label>
1610+
</div>
16071611
</section>
16081612
<section name="bounties">
16091613
<div class="header">Bounties</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.tt-show-fill-max [class*="rowWrapper__"] [class*="available__"] {
2+
align-items: flex-start;
3+
padding-top: 5px;
4+
}
5+
6+
.tt-show-fill-max [class*="rowWrapper__"] [class*="available__"]::after {
7+
content: "Fill Max";
8+
position: absolute;
9+
top: 20px;
10+
color: var(--tt-color-green);
11+
cursor: pointer;
12+
width: calc(100px - 2 * 7px);
13+
text-align: right;
14+
}
15+
16+
body:not(.tt-mobile):not(.tt-tablet) .tt-show-fill-max [class*="rowWrapper__"] [class*="available__"]:hover::after {
17+
color: #fff;
18+
background-color: var(--tt-color-green);
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,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+
})();

extension/scripts/global/globalData.js

+1
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ const DEFAULT_STORAGE = {
661661
itemmarket: {
662662
highlightCheapItems: new DefaultSetting({ type: "number|empty", defaultValue: "" }),
663663
leftBar: new DefaultSetting({ type: "boolean", defaultValue: false }),
664+
fillMax: new DefaultSetting({ type: "boolean", defaultValue: true }),
664665
},
665666
competition: {
666667
filter: new DefaultSetting({ type: "boolean", defaultValue: true }),

0 commit comments

Comments
 (0)