diff --git a/__tests__/priceService.test.ts b/__tests__/priceService.test.ts index 468641f..2ee36f9 100644 --- a/__tests__/priceService.test.ts +++ b/__tests__/priceService.test.ts @@ -94,7 +94,7 @@ describe('Price Service', () => { test('ItemPriceData.toString() returns formatted string', () => { const data = new ItemPriceData() data.sku = mockSku - data.update = mockDate + data.update = mockDate.getTime() data.ttl = mockTtl data.keys = 1 data.metal = 10.66 @@ -102,6 +102,8 @@ describe('Price Service', () => { const result = data.toString() expect(result).toContain(`Price for ${mockSku}`) + expect(result).toContain(mockDate.toString()) + expect(result).toContain(new Date(mockDate.getTime() + mockTtl).toString()) expect(result).toContain(`"keys":${data.keys}`) expect(result).toContain(`"metal":${data.metal}`) expect(result).toContain(`"scmPrice":${data.scmPrice}`) diff --git a/package.json b/package.json index a582708..04fa4d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tf2wikipricing", - "version": "0.4.0", + "version": "0.4.1", "description": "Adds item pricing to the Team Fortress 2 wiki", "devDependencies": { "@happy-dom/global-registrator": "^17.4.4", diff --git a/src/content/content.ts b/src/content/content.ts index 052cf9e..c41d706 100644 --- a/src/content/content.ts +++ b/src/content/content.ts @@ -11,7 +11,7 @@ import { findFirstElement, findFirstChildElement } from './utils/dom' import { extractPageTitleFromURL } from './utils/url'; var itemSchema: ItemSchema | null; -var pageLocale: string = 'en' +var locale: string = 'en' /** Exclude these from the pricelist. */ const excludedQualities = new Set([ @@ -31,7 +31,6 @@ async function inject() { // Not an item page return; } - const locale = extractLocaleFromURL(document.URL); var itemIndex: number | null = null; var itemName: string | null = null; @@ -251,7 +250,7 @@ async function inject() { }).reverse().forEach((element) => { priceInfoboxHeadingRow.insertAdjacentElement('afterend', element.row); }) - if(!updateTime) { updateTime = new Date() } + if(!updateTime || !(updateTime instanceof Date) || isNaN(+updateTime)) updateTime = new Date() // Footer row const row = document.createElement("tr"); @@ -283,7 +282,7 @@ prepareSchema().then(function (schema) { wipeSchema(); // FIXME: ugly hack. requires additional page reload. if prepareSchema returns null, we should handle it properly return; } - pageLocale = extractLocaleFromURL(document.URL) + locale = extractLocaleFromURL(document.URL) addStyles(); inject(); // TODO: Purge expired price data diff --git a/src/content/priceService.ts b/src/content/priceService.ts index 0fe7eaa..5aa675d 100644 --- a/src/content/priceService.ts +++ b/src/content/priceService.ts @@ -7,8 +7,8 @@ import { logDebug, log } from "./utils/log" export class ItemPriceData { /** Item SKU. */ sku: string - /** Date updated. */ - update: Date + /** Date updated, as Unix timestamp. */ + update: number /** TTL in milliseconds. */ ttl: number /** Price in keys. */ @@ -19,7 +19,7 @@ export class ItemPriceData { scmPrice: number toString(): string { - return `Price for ${this.sku}, fetched ${this.update} (expires ${this.update.getTime() + this.ttl})\n` + + return `Price for ${this.sku}, fetched ${new Date(this.update)} (expires ${new Date(this.update + this.ttl)})\n` + JSON.stringify({ keys: this.keys, metal: this.metal, @@ -43,8 +43,8 @@ export async function fetchPrice(token: string, sku: string, update: Date = new return new Promise(async (resolve, reject) => { var data: ItemPriceData | null - const cached = await getStorageValue(storage_priceprefix + sku, null) - if (cached != null && 'keys' in cached && 'metal' in cached) { + const cached: ItemPriceData = await getStorageValue(storage_priceprefix + sku, null) + if (cached != null && 'keys' in cached && 'metal' in cached && !isNaN(cached.update)) { data = cached } @@ -55,7 +55,7 @@ export async function fetchPrice(token: string, sku: string, update: Date = new } data = new ItemPriceData() data.sku = sku - data.update = update + data.update = update.getTime() data.ttl = ttl try { diff --git a/src/content/utils/formatting.ts b/src/content/utils/formatting.ts index 25083db..3ac4b9c 100644 --- a/src/content/utils/formatting.ts +++ b/src/content/utils/formatting.ts @@ -14,7 +14,7 @@ export function formatPrice(keys: number, metal: number, keyPrice: number, local if(keys > 0) { output += (formattedKeys == 1.0 ? $T("%@ key") : $T("%@ keys")).replace('%@', formattedKeys.toLocaleString(locale)) } else { - output += `${(+toFixed(metal, 2)).toLocaleString(locale)} ref` + output += $T("%@ ref").replace('%@', (+toFixed(metal, 2)).toLocaleString(locale)) } const currencyFormatter = new Intl.NumberFormat(locale, { minimumFractionDigits: 2, diff --git a/src/strings/en.js b/src/strings/en.js index 36dd116..d281096 100644 --- a/src/strings/en.js +++ b/src/strings/en.js @@ -10,6 +10,7 @@ module.exports = { // Price strings "Data unavailable": "Data unavailable", // sourced from AppleGlot + "%@ ref": "%@ ref", "%@ key": "%@ key", "%@ keys": "%@ keys", @@ -20,5 +21,6 @@ module.exports = { "Unique": "Unique", "Strange": "Strange", "Collector's": "Collector's", - "Haunted": "Haunted" + "Haunted": "Haunted", + "Australium": "Australium" } \ No newline at end of file diff --git a/src/strings/es.js b/src/strings/es.js index 788f147..2f464ba 100644 --- a/src/strings/es.js +++ b/src/strings/es.js @@ -10,6 +10,7 @@ module.exports = { // Price strings "Data unavailable": "Datos no disponibles", // sourced from AppleGlot + "%@ ref": "%@ ref", "%@ key": "%@ llave", "%@ keys": "%@ llaves", @@ -20,5 +21,6 @@ module.exports = { "Unique": "de Calidad Única", "Strange": "de Calidad Rara", "Collector's": "de Coleccionista", - "Haunted": "de Calidad Embrujada" + "Haunted": "de Calidad Embrujada", + "Australium": "de Australium" } \ No newline at end of file diff --git a/src/strings/it.js b/src/strings/it.js index d4a3463..961fa57 100644 --- a/src/strings/it.js +++ b/src/strings/it.js @@ -1,16 +1,26 @@ module.exports = { + // Generic button text, %@ is always a URL (eg. backpack.tf) "View listings on %@": "Voir les offres sur %@", + + // Itembox header "Community Pricing": "Community Pricing", - "Updated %@": "Updated %@", - "From %@": "From %@", - "Data unavailable": "Data unavailable", + // Itembox footer + "Updated %@": "Updated %@.", + "Trade prices sourced from %@. Currency conversions are approximate.": "Trade prices sourced from %@. Currency conversions are approximate.", // %@ is always a URL, (eg. prices.tf) + + // Price strings + "Data unavailable": "Data unavailable", // sourced from AppleGlot + "%@ ref": "%@ ref", "%@ key": "%@ key", "%@ keys": "%@ keys", + + // Item quality names, all sourced from TF2 wiki "Normal": "Normale", "Genuine": "Autentico", "Vintage": "Vintage", "Unique": "Unico", "Strange": "Strano", "Collector's": "Da collezione", - "Haunted": "Stregato" + "Haunted": "Stregato", + "Australium": "Australium" } \ No newline at end of file diff --git a/src/strings/ja.js b/src/strings/ja.js index 43315d1..01b1528 100644 --- a/src/strings/ja.js +++ b/src/strings/ja.js @@ -10,8 +10,9 @@ module.exports = { // Price strings "Data unavailable": "データがありません", // sourced from AppleGlot - "%@ key": "%@ key", - "%@ keys": "%@ keys", + "%@ ref": "%@精錬メタル", + "%@ key": "%@個の鍵", + "%@ keys": "%@個の鍵", // Item quality names, all sourced from TF2 wiki "Normal": "ノーマル", @@ -20,5 +21,6 @@ module.exports = { "Unique": "専用", "Strange": "ストレンジ", "Collector's": "Collector's", - "Haunted": "Haunted" + "Haunted": "Haunted", + "Australium": "オーストラリウム" } \ No newline at end of file