-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding feature to highlight items in the Bazaar when it's below the v…
…endor 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
- Loading branch information
1 parent
5045f9b
commit 94ea95a
Showing
8 changed files
with
104 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
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
7 changes: 7 additions & 0 deletions
7
extension/scripts/features/bazaar-sub-vendor-items/ttSubVendorPriceItems.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,7 @@ | ||
.tt-sub-vendor-highlight { | ||
background-color: var(--tt-color-green--40) !important; | ||
} | ||
|
||
.tt-sub-vendor-highlight [class*=buyForm___] { | ||
background-color: #f1f1f1 !important; | ||
} |
70 changes: 70 additions & 0 deletions
70
extension/scripts/features/bazaar-sub-vendor-items/ttSubVendorPriceItems.entry.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,70 @@ | ||
"use strict"; | ||
|
||
(async () => { | ||
await featureManagerLoaded(); | ||
|
||
const CLASS_NAME = "tt-sub-vendor-highlight"; | ||
let observer; | ||
|
||
// noinspection JSIncompatibleTypesComparison | ||
featureManager.registerFeature( | ||
"Highlight Cheap Items", | ||
"bazaar", | ||
() => settings.pages.bazaar.highlightSubVendorItems !== "", | ||
initialise, | ||
highlightEverything, | ||
removeHighlights, | ||
{ | ||
storage: ["settings.pages.bazaar.highlightSubVendorItems"], | ||
}, | ||
() => { | ||
if (!hasAPIData()) return "No API access."; | ||
} | ||
); | ||
|
||
async function initialise() { | ||
observer = new MutationObserver(() => { highlightEverything() }); | ||
observer.observe(document.body, { | ||
childList: true, | ||
subtree: true | ||
}); | ||
} | ||
|
||
function highlightEverything() { | ||
const items = [...document.findAll("[class*='item__'] > [class*='itemDescription__']")] | ||
.map((element) => { | ||
return { | ||
element, | ||
id: element.find("img").src.getNumber(), | ||
price: element.find("[class*='price___']").textContent.getNumber() | ||
} | ||
}) | ||
.filter((item) => item.element); | ||
|
||
items.forEach((item) => handleItem(item)); | ||
} | ||
|
||
/** | ||
* Should highlight the given item based on the price? | ||
* @param id {number|string} | ||
* @param price {number} | ||
* @returns {boolean} | ||
*/ | ||
function shouldHighlight(id, price) { | ||
return price < torndata.items[id]?.sell_price; | ||
} | ||
|
||
function handleItem(item) { | ||
if (shouldHighlight(item.id, item.price)) { | ||
item.element.parentElement.classList.add(CLASS_NAME); | ||
} else { | ||
item.element.parentElement.classList.remove(CLASS_NAME); | ||
} | ||
} | ||
|
||
function removeHighlights() { | ||
observer?.disconnect(); | ||
document.findAll(`.${CLASS_NAME}`) | ||
.forEach((item) => item.classList.remove(CLASS_NAME)); | ||
} | ||
})(); |
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