feat: enable webextension builds

Currently only supports Chrome due to no `chrome` -> `browser` polyfill
This commit is contained in:
xenticore
2025-05-01 15:27:14 -04:00
parent d02bd7ac9d
commit 95ce637892
15 changed files with 281 additions and 53 deletions

View File

@@ -2,6 +2,8 @@ import { defindex_key, storage_priceprefix } from "./config"
import { priceUsingPricesTF } from "./pricing/pricestf"
import { getStorageValue, setStorageValue } from "./storage"
import { logDebug } from "./utils/log"
declare const __ENV_WEBEXTENSION: boolean;
declare const __ENV_USERSCRIPT: boolean;
/** Pricing data for a given TF2 item. */
export class ItemPriceData {
@@ -58,7 +60,12 @@ export async function fetchPrice(token: string, sku: string, update: Date = new
data.ttl = ttl
try {
const response = await priceUsingPricesTF(token, sku)
let response: PricesResponse
if(__ENV_USERSCRIPT) {
response = await priceUsingPricesTF(token, sku)
} else {
response = JSON.parse(await chrome.runtime.sendMessage({contentScriptQuery: "priceSKU", service: "prices.tf", sku: sku, token: token}));
}
if (response) {
data.keys = response.keys
data.metal = response.metal