From 0a52bca2294e5a1027dae97fc0f63f947b4c0ead Mon Sep 17 00:00:00 2001 From: xenticore Date: Fri, 28 Mar 2025 23:59:14 -0400 Subject: [PATCH 1/6] fix: redundant page locale check --- src/content/content.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/content/content.ts b/src/content/content.ts index 052cf9e..a8ce368 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; @@ -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 From 04845d6bbf615db1b5d76d7660f41d3764faae31 Mon Sep 17 00:00:00 2001 From: xenticore Date: Sat, 29 Mar 2025 00:00:52 -0400 Subject: [PATCH 2/6] l10n: translate ref --- src/content/utils/formatting.ts | 2 +- src/strings/en.js | 1 + src/strings/es.js | 1 + src/strings/ja.js | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) 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..83106e0 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", diff --git a/src/strings/es.js b/src/strings/es.js index 788f147..edae345 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", diff --git a/src/strings/ja.js b/src/strings/ja.js index 43315d1..2b8b43f 100644 --- a/src/strings/ja.js +++ b/src/strings/ja.js @@ -10,6 +10,7 @@ module.exports = { // Price strings "Data unavailable": "データがありません", // sourced from AppleGlot + "%@ ref": "%@精錬メタル", "%@ key": "%@ key", "%@ keys": "%@ keys", From c9628de4c628fd3d4f058afc2dba709be3612f70 Mon Sep 17 00:00:00 2001 From: xenticore Date: Sat, 29 Mar 2025 00:01:19 -0400 Subject: [PATCH 3/6] l10n: add australium localization --- src/strings/en.js | 3 ++- src/strings/es.js | 3 ++- src/strings/ja.js | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/strings/en.js b/src/strings/en.js index 83106e0..d281096 100644 --- a/src/strings/en.js +++ b/src/strings/en.js @@ -21,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 edae345..2f464ba 100644 --- a/src/strings/es.js +++ b/src/strings/es.js @@ -21,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/ja.js b/src/strings/ja.js index 2b8b43f..01b1528 100644 --- a/src/strings/ja.js +++ b/src/strings/ja.js @@ -11,8 +11,8 @@ module.exports = { // Price strings "Data unavailable": "データがありません", // sourced from AppleGlot "%@ ref": "%@精錬メタル", - "%@ key": "%@ key", - "%@ keys": "%@ keys", + "%@ key": "%@個の鍵", + "%@ keys": "%@個の鍵", // Item quality names, all sourced from TF2 wiki "Normal": "ノーマル", @@ -21,5 +21,6 @@ module.exports = { "Unique": "専用", "Strange": "ストレンジ", "Collector's": "Collector's", - "Haunted": "Haunted" + "Haunted": "Haunted", + "Australium": "オーストラリウム" } \ No newline at end of file From 13a8e142848b1e8b1dca29946e87cfc855572576 Mon Sep 17 00:00:00 2001 From: xenticore Date: Sat, 29 Mar 2025 00:03:43 -0400 Subject: [PATCH 4/6] l10n: update italian strings --- src/strings/it.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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 From be6206194bb9e6cb58cc2ccf6024ef22c3dfba97 Mon Sep 17 00:00:00 2001 From: xenticore Date: Sat, 29 Mar 2025 14:19:38 -0400 Subject: [PATCH 5/6] fix: price data update time serialization price update time was not properly serialized as a number like the schema was, and led to dates being stored as empty objects. UI code also did not check if date was NaN, and rendered "invalid date" instead. --- __tests__/priceService.test.ts | 4 +++- src/content/content.ts | 2 +- src/content/priceService.ts | 12 ++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) 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/src/content/content.ts b/src/content/content.ts index a8ce368..c41d706 100644 --- a/src/content/content.ts +++ b/src/content/content.ts @@ -250,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"); 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 { From 3101f57f620123e2c518108b2d49367f82a1eed0 Mon Sep 17 00:00:00 2001 From: xenticore Date: Sat, 29 Mar 2025 14:20:56 -0400 Subject: [PATCH 6/6] bump version to 0.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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",