From eada50c0e832e1e567ff844c49e9bbc20b4b4f6e Mon Sep 17 00:00:00 2001 From: xenticore Date: Mon, 7 Apr 2025 15:45:13 -0400 Subject: [PATCH] refactor: sort price rows by order instead of quality --- src/content/content.ts | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/content/content.ts b/src/content/content.ts index 088fea0..5f77613 100644 --- a/src/content/content.ts +++ b/src/content/content.ts @@ -188,7 +188,7 @@ async function inject() { var updateTime: Date | null = null; interface PriceRow { - quality: number + order: number row: HTMLTableRowElement } var priceRows: PriceRow[]= []; @@ -214,7 +214,7 @@ async function inject() { const qualityName = itemQualities[quality as unknown as keyof typeof itemQualities].toString() const priceRow = createPriceRow(qualityName, data, keyPrice, locale) - priceRows.push({quality: quality, row: priceRow}) + priceRows.push({order: quality == 6 ? -1 : quality, row: priceRow) }) // Check item schema for Australium variant of current defindex @@ -231,7 +231,7 @@ async function inject() { const priceRow = createPriceRow($T("Australium"), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Australium_weapons") - priceRows.push({quality: 99, row: priceRow}) + priceRows.push({order: 99, row: priceRow) resolve() return })) @@ -251,7 +251,7 @@ async function inject() { const priceRow = createPriceRow($T("Festive"), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Festive_weapons") - priceRows.push({quality: 97, row: priceRow}) + priceRows.push({order: -1, row: priceRow}) resolve() return })) @@ -267,7 +267,7 @@ async function inject() { const priceRow = createPriceRow($T("Strange Festive"), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Festive_weapons") - priceRows.push({quality: 98, row: priceRow}) + priceRows.push({order: 11, row: priceRow}) resolve() return })) @@ -275,14 +275,10 @@ async function inject() { Promise.all(promises).then(() => { priceRows.sort((a, b) => { - // Sort 6 first always, then numerically - if (a.quality === 6) { - return -1; - } else if (b.quality === 6) { - return 1; - } else { - return a.quality == b.quality ? a.quality < b.quality ? -1 : 1 : 0; + if (a.category != b.category) { + return a.category - b.category; } + return a.order - b.order; }).reverse().forEach((element) => { priceInfoboxHeadingRow.insertAdjacentElement('afterend', element.row); })