Skip to content

Commit

Permalink
Update and remove existing features to work after the market overhaul. (
Browse files Browse the repository at this point in the history
#813)

* Remove the bazaar and item market redirect feature.

* Make it easier to identify the page.

* Adapt cheap item highlights to work with the item market overhaul.

* Update version titles.

* Solve issue with fetch listener body.

* Cleanup item market script.

* Follow updates of the sellers list.

* Follow updates of the item.

* Remove the item market no confirm feature

* Mobile support for the cheap item market feature.

* Adapt drug details to work with the item market overhaul.
  • Loading branch information
DeKleineKobini authored Oct 29, 2024
1 parent f2a55e4 commit 1e674f6
Show file tree
Hide file tree
Showing 20 changed files with 3,312 additions and 3,408 deletions.
4,258 changes: 2,131 additions & 2,127 deletions extension/changelog.json

Large diffs are not rendered by default.

1,712 changes: 853 additions & 859 deletions extension/manifest.json

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions extension/pages/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -1195,14 +1195,6 @@ <h2>
<input id="bazaar-maxBuyIgnoreCash" type="checkbox" />
<label for="bazaar-maxBuyIgnoreCash">Ignore cash on hand for fill max button.</label>
</div>
<div class="option no-mobile">
<input id="bazaar-redirects" type="checkbox" />
<label for="bazaar-redirects">Highlight the searched item from the item market.</label>
</div>
<div class="option tabbed no-mobile">
<input id="bazaar-redirectsScroll" type="checkbox" />
<label for="bazaar-redirectsScroll">Scroll to the correct item automatically.</label>
</div>
</section>
<section name="gym">
<div class="header">Gym</div>
Expand Down Expand Up @@ -1605,10 +1597,6 @@ <h2>
<label for="noConfirm-tradeAccept">Accepting a trade.</label>
<label class="note" for="noConfirm-tradeAccept">You are responsible for making sure the trade isn't a scam.</label>
</div>
<div class="option">
<input id="noConfirm-marketBuy" type="checkbox" />
<label for="noConfirm-marketBuy">Buying items on the item market.</label>
</div>
<div class="option">
<input id="noConfirm-pointsMarketBuy" type="checkbox" />
<label for="noConfirm-pointsMarketBuy">Buying points from the points market.</label>
Expand Down
87 changes: 87 additions & 0 deletions extension/scripts/content/itemmarket/ttItemMarket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"use strict";

(async () => {
const { mobile, tablet } = await checkDevice();

addFetchListener(({ detail: { page, json, fetch } }) => {
if (page !== "page" || !json) return;

const params = new URL(fetch.url).searchParams;
const sid = params.get("sid");
if (sid !== "iMarket") return;

const step = params.get("step");

if (step === "getShopList" || step === "searchItem") {
requireElement("[class*='itemList___'],[class*='noItems___']").then(handleItemList);
} else if (step === "getListing") {
requireElement("[class*='sellerList___']").then((list) => handleSellerList(list, fetch.body?.itemID));
}
});

const root = document.find("#item-market-root");

const hash = getHashParameters();
const view = hash.get("market/view");
if (view === "category" || view === "search") {
requireElement("[class*='itemList___'],[class*='noItems___']").then(handleItemList);
}
if (view === "search" && hash.has("itemID")) {
requireElement("[class*='sellerList___']").then((list) => handleSellerList(list, parseInt(hash.get("itemID"))));
}
if (mobile || tablet) {
new MutationObserver(async (mutations) => {
const itemInfo = mutations
.flatMap((mutation) => [...mutation.addedNodes])
.filter((node) => node.nodeType === Document.ELEMENT_NODE)
.find((element) => element.classList.contains("item-info"));
if (!itemInfo) return;

const item = parseInt(itemInfo.id.match(/wai-itemInfo-([0-9]+)-0/)[1]);

triggerCustomListener(EVENT_CHANNELS.ITEMMARKET_ITEM_DETAILS, { item, element: itemInfo });
}).observe(root, { childList: true, subtree: true });
}

function isValidEntry(list) {
return !list.className.includes("[class*='noItems___']");
}

function handleItemList(list) {
if (!isValidEntry(list)) return;

triggerCustomListener(EVENT_CHANNELS.ITEMMARKET_CATEGORY_ITEMS, { list });
[...list.findAll("[class*='itemList___'] > li:first-child")].forEach((itemElement) => {
new MutationObserver(() => {
triggerCustomListener(EVENT_CHANNELS.ITEMMARKET_CATEGORY_ITEMS_UPDATE, { item: itemElement });
}).observe(itemElement.find("[class*='priceAndTotal___'] span:first-child"), { subtree: true, characterData: true });
});
if (!mobile && !tablet) {
new MutationObserver(async (mutations) => {
const infoWrapper = mutations
.flatMap((mutation) => [...mutation.addedNodes])
.filter((node) => node.nodeType === Document.ELEMENT_NODE)
.find((element) => element.className.includes("itemInfoWrapper___"));
if (!infoWrapper) return;

await requireElement(".tornPreloader", { invert: true });

const item = parseInt(infoWrapper.find("img").src.match(/https:\/\/www\.torn\.com\/images\/items\/([0-9]+)\/.*\.png/)[1]);

triggerCustomListener(EVENT_CHANNELS.ITEMMARKET_ITEM_DETAILS, { item, element: infoWrapper });
}).observe(list, { childList: true });
}
}

function handleSellerList(list, item) {
if (!isValidEntry(list)) return;

triggerCustomListener(EVENT_CHANNELS.ITEMMARKET_ITEMS, { item, list });
new MutationObserver((mutations) => {
const addedNodes = mutations.flatMap((mutation) => [...mutation.addedNodes]);
if (addedNodes.length <= 0) return;

triggerCustomListener(EVENT_CHANNELS.ITEMMARKET_ITEMS_UPDATE, { item, list });
}).observe(list, { childList: true });
}
})();

This file was deleted.

This file was deleted.

Loading

0 comments on commit 1e674f6

Please sign in to comment.