fix: prioritize non-stock/non-decorated items

Changed schema lookups to prioritize non-stock/non-decorated item defindexes when names collide
Modified unit tests to include example (stock Flame Thrower)
This commit is contained in:
xenticore
2025-03-27 15:32:45 -04:00
parent b24cda98ad
commit 967a32fc83
3 changed files with 35 additions and 20 deletions

View File

@@ -35,24 +35,10 @@ async function inject() {
var itemIndex: number | null = null;
var itemName: string | null = null;
// Try using buy buttons, if they exist
// Find buy buttons
const buyButton = findFirstChildElement('.btn_buynow', itemInfobox);
const marketButton = findFirstChildElement('.btn_buynow_market', itemInfobox);
if(buyButton) {
const link = (buyButton.parentElement as HTMLLinkElement);
if(link && link.href) {
itemIndex = parseInt(link.href.replace('https://store.steampowered.com/buyitem/440/', ''));
}
}
if(!itemIndex && marketButton) {
const link = (marketButton.parentElement as HTMLLinkElement);
if(link && link.href) {
itemIndex = parseInt(link.href.replace('https://steamcommunity.com/market/search/?q=appid:440+prop_def_index:', ''));
}
}
// Try using item name
const header = findFirstChildElement('.infobox-header', itemInfobox);
if (!itemIndex && header) {
@@ -72,6 +58,23 @@ async function inject() {
}
}
// Try using buy buttons, if they exist
if(!itemIndex) {
if(buyButton) {
const link = (buyButton.parentElement as HTMLLinkElement);
if(link && link.href) {
itemIndex = parseInt(link.href.replace('https://store.steampowered.com/buyitem/440/', ''));
}
}
if(!itemIndex && marketButton) {
const link = (marketButton.parentElement as HTMLLinkElement);
if(link && link.href) {
itemIndex = parseInt(link.href.replace('https://steamcommunity.com/market/search/?q=appid:440+prop_def_index:', ''));
}
}
}
if (!itemIndex) {
// Cannot continue without index
logError(itemName ? `Could not find defindex for ${itemName}` : `Could not determine item defindex or name`);