Merge branch 'develop'

This commit is contained in:
xenticore
2025-03-29 14:21:16 -04:00
9 changed files with 39 additions and 22 deletions

View File

@@ -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}`)

View File

@@ -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",

View File

@@ -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

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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"
}

View File

@@ -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": "オーストラリウム"
}