diff --git a/src/content/content.ts b/src/content/content.ts index d0efdc7..4e91169 100644 --- a/src/content/content.ts +++ b/src/content/content.ts @@ -3,7 +3,7 @@ import styleCss from './style.css' import { logDebug, log, logError } from './utils/log' import { getPricesToken, priceUsingPricesTF } from './pricing/pricestf' import itemQualities from 'tf2-static-schema/static/qualities.json'; -import { getItemIndexByName, getTradableStatusByDefindex, ItemSchema, prepareSchema, wipeSchema } from './schemaService' +import { getItemIndexByName, getTradableStatusByDefindex, ItemSchema, ItemSlot, prepareSchema, wipeSchema } from './schemaService' import { $T, extractLocaleFromURL } from './utils/localization' import { fetchPrice, fetchKeyPrice, ItemPriceData } from './priceService' import { createPriceRow, createStoreButton } from './uiRenderer' @@ -190,7 +190,8 @@ async function inject() { enum PriceRowCategory { None, Festive, - Botkiller + Botkiller, + KillstreakKit } interface PriceRow { @@ -291,6 +292,51 @@ async function inject() { })) } + var killstreakKitHeadingRow: HTMLTableRowElement | null + // Check for Killstreak Kits + if(itemSchema[itemIndex].slot == ItemSlot.Primary || + itemSchema[itemIndex].slot == ItemSlot.Secondary || + itemSchema[itemIndex].slot == ItemSlot.Melee) + { + /// Create subheading + killstreakKitHeadingRow = document.createElement("tr") + const heading = document.createElement("th") + heading.className = "infobox-subheader" + heading.colSpan = 2 + heading.innerText = $T("Killstreak Kit") + heading.style.fontSize = '1em'; + heading.style.backgroundColor = '#F5C087'; + killstreakKitHeadingRow.style.display = 'none'; + killstreakKitHeadingRow.appendChild(heading); + [1,2,3].map((tier) => { + promises.push(new Promise(async (resolve) => { + logDebug(`Fetching price for ${itemName} Killstreak Kit Tier ${tier}`) + var data: ItemPriceData | null + try { + var kitIndex: number + switch (tier) { + default: + case 1: kitIndex = 6527; break; + case 2: kitIndex = 6523; break; + case 3: kitIndex = 6526; break; + } + data = await fetchPrice(token, `${kitIndex};6;uncraftable;kt-${tier};td-${itemIndex}`, currentTime); + updateTime = new Date(data.update) + } catch { + log(`${itemName} Killstreak Kit Tier ${tier} is unpriced or unavailable, skipping...`) + resolve() + return + } + + const priceRow = createPriceRow($T(`kt-${tier}`), data, keyPrice, locale, "https://wiki.teamfortress.com/wiki/Killstreak_Kit") + + priceRows.push({order: tier, row: priceRow, category: PriceRowCategory.KillstreakKit}) + resolve() + return + })) + }) + } + // Silver Mk.I, Gold Mk.II, Rust, Blood, Carbonado, Diamond, Silver Mk.II, Gold Mk.II const botkillerOrder = [ "Silver", @@ -339,6 +385,7 @@ async function inject() { }) } + if(killstreakKitHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', killstreakKitHeadingRow); if(botKillerHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', botKillerHeadingRow); if(festiveHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', festiveHeadingRow); @@ -359,6 +406,9 @@ async function inject() { case PriceRowCategory.Botkiller: botKillerHeadingRow.insertAdjacentElement('afterend', element.row); break; + case PriceRowCategory.KillstreakKit: + killstreakKitHeadingRow.insertAdjacentElement('afterend', element.row); + killstreakKitHeadingRow.style.display = 'revert'; } }) if(!updateTime || !(updateTime instanceof Date) || isNaN(+updateTime)) updateTime = new Date()