Skip to content

Commit 94ea95a

Browse files
Adding feature to highlight items in the Bazaar when it's below the vendor price. (#835)
- requires turning it on in options - requires an API key - works in FF & Chrome; including when the viewport is small (e.g., mobile sized) - updated manifest for new files - updated CONTRIBUTING for a bit more on testing in browsers - added option to settings & global defaults
1 parent 5045f9b commit 94ea95a

File tree

8 files changed

+104
-3
lines changed

8 files changed

+104
-3
lines changed

CONTRIBUTING.md

+5
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ We have prettier formatting to help you follow our coding conventions.
7878

7979
## Development Tips
8080

81+
### Testing
82+
83+
* Chrome: [load an unpacked extension](https://developer.chrome.com/docs/extensions/get-started/tutorial/hello-world#load-unpacked)
84+
* Firefox: [install a temporary extension](https://extensionworkshop.com/documentation/develop/temporary-installation-in-firefox/)
85+
8186
##### Ignore local manifest.json changes.
8287

8388
This can be used to remove the Firefox only setting to avoid warnings in Chromium-browsers.

extension/changelog.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"fixes": [{ "message": "Fix the company id showing something wrong.", "contributor": "DeKleineKobini" }],
99
"changes": [
1010
{ "message": "Change layout of preferences page on mobiles.", "contributor": "TheFoxMan" },
11-
{ "message": "Correctly list Love Juice cooldown.", "contributor": "TheFoxMan" }
11+
{ "message": "Correctly list Love Juice cooldown.", "contributor": "TheFoxMan" },
12+
{ "message": "Option to highlight items in Bazaars that have a ccost less than the vendor price.", "contributor": "TravisTheTechie" }
1213
],
1314
"removed": []
1415
}

extension/manifest.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,14 @@
247247
},
248248
{
249249
"matches": ["https://www.torn.com/bazaar.php*"],
250-
"css": ["scripts/features/bazaar-worth/ttBazaarWorth.css"],
251-
"js": ["scripts/features/bazaar-worth/ttBazaarWorth.entry.js"],
250+
"css": [
251+
"scripts/features/bazaar-worth/ttBazaarWorth.css",
252+
"scripts/features/bazaar-sub-vendor-items/ttSubVendorPriceItems.css"
253+
],
254+
"js": [
255+
"scripts/features/bazaar-worth/ttBazaarWorth.entry.js",
256+
"scripts/features/bazaar-sub-vendor-items/ttSubVendorPriceItems.entry.js"
257+
],
252258
"run_at": "document_start"
253259
},
254260
{

extension/pages/settings/settings.html

+4
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,10 @@ <h2>
12351235
<input id="bazaar-maxBuyIgnoreCash" type="checkbox" />
12361236
<label for="bazaar-maxBuyIgnoreCash">Ignore cash on hand for fill max button.</label>
12371237
</div>
1238+
<div class="option">
1239+
<input id="bazaar-highlightSubVendorItems" type="checkbox" />
1240+
<label for="bazaar-highlightSubVendorItems">Highlight items less than the vendor sell price.</label>
1241+
</div>
12381242
</section>
12391243
<section name="gym">
12401244
<div class="header">Gym</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.tt-sub-vendor-highlight {
2+
background-color: var(--tt-color-green--40) !important;
3+
}
4+
5+
.tt-sub-vendor-highlight [class*=buyForm___] {
6+
background-color: #f1f1f1 !important;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"use strict";
2+
3+
(async () => {
4+
await featureManagerLoaded();
5+
6+
const CLASS_NAME = "tt-sub-vendor-highlight";
7+
let observer;
8+
9+
// noinspection JSIncompatibleTypesComparison
10+
featureManager.registerFeature(
11+
"Highlight Cheap Items",
12+
"bazaar",
13+
() => settings.pages.bazaar.highlightSubVendorItems !== "",
14+
initialise,
15+
highlightEverything,
16+
removeHighlights,
17+
{
18+
storage: ["settings.pages.bazaar.highlightSubVendorItems"],
19+
},
20+
() => {
21+
if (!hasAPIData()) return "No API access.";
22+
}
23+
);
24+
25+
async function initialise() {
26+
observer = new MutationObserver(() => { highlightEverything() });
27+
observer.observe(document.body, {
28+
childList: true,
29+
subtree: true
30+
});
31+
}
32+
33+
function highlightEverything() {
34+
const items = [...document.findAll("[class*='item__'] > [class*='itemDescription__']")]
35+
.map((element) => {
36+
return {
37+
element,
38+
id: element.find("img").src.getNumber(),
39+
price: element.find("[class*='price___']").textContent.getNumber()
40+
}
41+
})
42+
.filter((item) => item.element);
43+
44+
items.forEach((item) => handleItem(item));
45+
}
46+
47+
/**
48+
* Should highlight the given item based on the price?
49+
* @param id {number|string}
50+
* @param price {number}
51+
* @returns {boolean}
52+
*/
53+
function shouldHighlight(id, price) {
54+
return price < torndata.items[id]?.sell_price;
55+
}
56+
57+
function handleItem(item) {
58+
if (shouldHighlight(item.id, item.price)) {
59+
item.element.parentElement.classList.add(CLASS_NAME);
60+
} else {
61+
item.element.parentElement.classList.remove(CLASS_NAME);
62+
}
63+
}
64+
65+
function removeHighlights() {
66+
observer?.disconnect();
67+
document.findAll(`.${CLASS_NAME}`)
68+
.forEach((item) => item.classList.remove(CLASS_NAME));
69+
}
70+
})();

extension/scripts/global/globalData.js

+1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ const DEFAULT_STORAGE = {
570570
worth: new DefaultSetting({ type: "boolean", defaultValue: true }),
571571
fillMax: new DefaultSetting({ type: "boolean", defaultValue: true }),
572572
maxBuyIgnoreCash: new DefaultSetting({ type: "boolean", defaultValue: false }),
573+
highlightSubVendorItems: new DefaultSetting({ type: "boolean", defaultValue: false }),
573574
},
574575
trade: {
575576
itemValues: new DefaultSetting({ type: "boolean", defaultValue: true }),

extension/scripts/global/team.js

+7
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ const TEAM = [
217217
torn: 2383326,
218218
color: "white", // No explicit color chosen.
219219
},
220+
{
221+
name: "TravisTheTechie",
222+
title: "Developer",
223+
core: false,
224+
torn: 3549588,
225+
color: "firebrick",
226+
},
220227
];
221228

222229
const CONTRIBUTORS = TEAM.filter(({ title, color }) => title.includes("Developer") || color).reduce(

0 commit comments

Comments
 (0)