You've already forked tf2wikipricing
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:
@@ -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`);
|
||||
|
||||
@@ -16,10 +16,13 @@ function isDateAfterOneDay(date1: Date, date2: Date): boolean {
|
||||
|
||||
export class ItemSchema { [key: string]: {name: string, tradable: Boolean}; }
|
||||
|
||||
export function getItemIndexByName(schema: ItemSchema, name: string) {
|
||||
export function getItemIndexByName(schema: ItemSchema, name: string, excludeStock: Boolean = true, excludeDecorated: Boolean = true) {
|
||||
for (const [defindex, value] of Object.entries(schema)) {
|
||||
if (value['name'] == name) {
|
||||
return parseInt(defindex)
|
||||
const index = parseInt(defindex)
|
||||
if(excludeStock && index <= 30) continue
|
||||
if(excludeDecorated && (index >= 15000 && index < 16000)) continue
|
||||
return index
|
||||
}
|
||||
}
|
||||
return null
|
||||
@@ -29,9 +32,12 @@ export function getTradableStatusByDefindex(schema: ItemSchema, defindex: number
|
||||
return schema[defindex.toString()].tradable
|
||||
}
|
||||
|
||||
export function getTradableStatusByName(schema: ItemSchema, name: string) {
|
||||
export function getTradableStatusByName(schema: ItemSchema, name: string, excludeStock: Boolean = true, excludeDecorated = true,) {
|
||||
for (const [defindex, value] of Object.entries(schema)) {
|
||||
if (value['name'] == name) {
|
||||
const index = parseInt(defindex)
|
||||
if(excludeStock && index <= 30) continue
|
||||
if(excludeDecorated && (index >= 15000 && index < 16000)) continue
|
||||
return value.tradable
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user