feat: add killstreak kit pricing

This commit is contained in:
xenticore
2025-04-07 17:27:30 -04:00
parent 7be1d1da5d
commit 3966c79b85

View File

@@ -3,7 +3,7 @@ import styleCss from './style.css'
import { logDebug, log, logError } from './utils/log' import { logDebug, log, logError } from './utils/log'
import { getPricesToken, priceUsingPricesTF } from './pricing/pricestf' import { getPricesToken, priceUsingPricesTF } from './pricing/pricestf'
import itemQualities from 'tf2-static-schema/static/qualities.json'; 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 { $T, extractLocaleFromURL } from './utils/localization'
import { fetchPrice, fetchKeyPrice, ItemPriceData } from './priceService' import { fetchPrice, fetchKeyPrice, ItemPriceData } from './priceService'
import { createPriceRow, createStoreButton } from './uiRenderer' import { createPriceRow, createStoreButton } from './uiRenderer'
@@ -190,7 +190,8 @@ async function inject() {
enum PriceRowCategory { enum PriceRowCategory {
None, None,
Festive, Festive,
Botkiller Botkiller,
KillstreakKit
} }
interface PriceRow { 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 // Silver Mk.I, Gold Mk.II, Rust, Blood, Carbonado, Diamond, Silver Mk.II, Gold Mk.II
const botkillerOrder = [ const botkillerOrder = [
"Silver", "Silver",
@@ -339,6 +385,7 @@ async function inject() {
}) })
} }
if(killstreakKitHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', killstreakKitHeadingRow);
if(botKillerHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', botKillerHeadingRow); if(botKillerHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', botKillerHeadingRow);
if(festiveHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', festiveHeadingRow); if(festiveHeadingRow) priceInfoboxHeadingRow.insertAdjacentElement('afterend', festiveHeadingRow);
@@ -359,6 +406,9 @@ async function inject() {
case PriceRowCategory.Botkiller: case PriceRowCategory.Botkiller:
botKillerHeadingRow.insertAdjacentElement('afterend', element.row); botKillerHeadingRow.insertAdjacentElement('afterend', element.row);
break; break;
case PriceRowCategory.KillstreakKit:
killstreakKitHeadingRow.insertAdjacentElement('afterend', element.row);
killstreakKitHeadingRow.style.display = 'revert';
} }
}) })
if(!updateTime || !(updateTime instanceof Date) || isNaN(+updateTime)) updateTime = new Date() if(!updateTime || !(updateTime instanceof Date) || isNaN(+updateTime)) updateTime = new Date()