From 779cd12153d8112842d84af697b556481be34ee9 Mon Sep 17 00:00:00 2001 From: xenticore Date: Mon, 7 Apr 2025 15:57:41 -0400 Subject: [PATCH] feat: add festive and botkiller categories to pricebox festives are now shown with their quality rather than "Festive" and "Strange Festive" botkillers are sorted by release, and displayed without "Mk.I" to save space --- src/content/content.ts | 93 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 7 deletions(-) diff --git a/src/content/content.ts b/src/content/content.ts index 5f77613..d0efdc7 100644 --- a/src/content/content.ts +++ b/src/content/content.ts @@ -187,9 +187,16 @@ async function inject() { var updateTime: Date | null = null; + enum PriceRowCategory { + None, + Festive, + Botkiller + } + interface PriceRow { order: number row: HTMLTableRowElement + category: PriceRowCategory } var priceRows: PriceRow[]= []; @@ -214,7 +221,7 @@ async function inject() { const qualityName = itemQualities[quality as unknown as keyof typeof itemQualities].toString() const priceRow = createPriceRow(qualityName, data, keyPrice, locale) - priceRows.push({order: quality == 6 ? -1 : quality, row: priceRow) + priceRows.push({order: quality == 6 ? -1 : quality, row: priceRow, category: PriceRowCategory.None}) }) // Check item schema for Australium variant of current defindex @@ -231,14 +238,25 @@ async function inject() { const priceRow = createPriceRow($T("Australium"), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Australium_weapons") - priceRows.push({order: 99, row: priceRow) + priceRows.push({order: 99, row: priceRow, category: PriceRowCategory.None}) resolve() return })) } + var festiveHeadingRow: HTMLTableRowElement | null // Check item schema for Festive variant of current defindex if(itemSchema[itemIndex].festiveVariant != null) { + /// Create subheading + festiveHeadingRow = document.createElement("tr") + const festiveHeading = document.createElement("th") + festiveHeading.className = "infobox-subheader" + festiveHeading.colSpan = 2 + festiveHeading.innerText = $T("Festive") + festiveHeading.style.fontSize = '1em'; + festiveHeading.style.backgroundColor = '#F5C087'; + festiveHeadingRow.appendChild(festiveHeading); + promises.push(new Promise(async (resolve) => { logDebug(`Fetching price for Festive ${itemName}`) var data: ItemPriceData | null @@ -249,9 +267,9 @@ async function inject() { log(`Festive ${itemName} is unpriced or unavailable, skipping...`) } - const priceRow = createPriceRow($T("Festive"), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Festive_weapons") + const priceRow = createPriceRow($T("Unique"), data, keyPrice, locale) - priceRows.push({order: -1, row: priceRow}) + priceRows.push({order: -1, row: priceRow, category: PriceRowCategory.Festive}) resolve() return })) @@ -265,14 +283,65 @@ async function inject() { log(`Strange Festive ${itemName} is unpriced or unavailable, skipping...`) } - const priceRow = createPriceRow($T("Strange Festive"), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Festive_weapons") + const priceRow = createPriceRow($T("Strange"), data, keyPrice, locale) - priceRows.push({order: 11, row: priceRow}) + priceRows.push({order: 11, row: priceRow, category: PriceRowCategory.Festive}) resolve() return })) } + // Silver Mk.I, Gold Mk.II, Rust, Blood, Carbonado, Diamond, Silver Mk.II, Gold Mk.II + const botkillerOrder = [ + "Silver", + "Gold", + "Rust", + "Blood", + "Carbonado", + "Diamond", + "Silver Mk.II", + "Gold Mk.II", + ] + var botKillerHeadingRow: HTMLTableRowElement | null + if(itemSchema[itemIndex].botkillerVariants != null && itemSchema[itemIndex].botkillerVariants.length > 0) { + /// Create subheading + botKillerHeadingRow = document.createElement("tr") + const festiveHeading = document.createElement("th") + festiveHeading.className = "infobox-subheader" + festiveHeading.colSpan = 2 + festiveHeading.innerText = $T("Botkiller") + festiveHeading.style.fontSize = '1em'; + festiveHeading.style.backgroundColor = '#F5C087'; + botKillerHeadingRow.appendChild(festiveHeading); + + itemSchema[itemIndex].botkillerVariants.map((variantIndex) => { + const itemName = itemSchema[variantIndex].name + // FIXME: variantName should match wiki display name + const variantName = itemName.includes('Mk.II') ? itemName.split(' ')[0] + ' Mk.II' : itemName.split(' ')[0] + promises.push(new Promise(async (resolve) => { + logDebug(`Fetching price for ${itemName}`) + var data: ItemPriceData | null + try { + data = await fetchPrice(token, `${variantIndex};11`, currentTime); + updateTime = new Date(data.update) + } catch { + log(`${itemName} is unpriced or unavailable, skipping...`) + } + + const priceRow = createPriceRow($T(variantName), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Botkiller_weapons") + + // FIXME: order should be by release + // Silver Mk.I, Gold Mk.II, Rust, Blood, Carbonado, Diamond, Silver Mk.II, Gold Mk.II + priceRows.push({order: botkillerOrder.indexOf(variantName), row: priceRow, category: PriceRowCategory.Botkiller}) + resolve() + return + })) + }) + } + + if(botKillerHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', botKillerHeadingRow); + if(festiveHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', festiveHeadingRow); + Promise.all(promises).then(() => { priceRows.sort((a, b) => { if (a.category != b.category) { @@ -280,7 +349,17 @@ async function inject() { } return a.order - b.order; }).reverse().forEach((element) => { - priceInfoboxHeadingRow.insertAdjacentElement('afterend', element.row); + switch(element.category) { + case PriceRowCategory.None: + priceInfoboxHeadingRow.insertAdjacentElement('afterend', element.row); + break; + case PriceRowCategory.Festive: + festiveHeadingRow.insertAdjacentElement('afterend', element.row); + break; + case PriceRowCategory.Botkiller: + botKillerHeadingRow.insertAdjacentElement('afterend', element.row); + break; + } }) if(!updateTime || !(updateTime instanceof Date) || isNaN(+updateTime)) updateTime = new Date()