You've already forked tf2wikipricing
Merge branch 'develop'
This commit is contained in:
@@ -94,7 +94,7 @@ describe('Price Service', () => {
|
|||||||
test('ItemPriceData.toString() returns formatted string', () => {
|
test('ItemPriceData.toString() returns formatted string', () => {
|
||||||
const data = new ItemPriceData()
|
const data = new ItemPriceData()
|
||||||
data.sku = mockSku
|
data.sku = mockSku
|
||||||
data.update = mockDate
|
data.update = mockDate.getTime()
|
||||||
data.ttl = mockTtl
|
data.ttl = mockTtl
|
||||||
data.keys = 1
|
data.keys = 1
|
||||||
data.metal = 10.66
|
data.metal = 10.66
|
||||||
@@ -102,6 +102,8 @@ describe('Price Service', () => {
|
|||||||
|
|
||||||
const result = data.toString()
|
const result = data.toString()
|
||||||
expect(result).toContain(`Price for ${mockSku}`)
|
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(`"keys":${data.keys}`)
|
||||||
expect(result).toContain(`"metal":${data.metal}`)
|
expect(result).toContain(`"metal":${data.metal}`)
|
||||||
expect(result).toContain(`"scmPrice":${data.scmPrice}`)
|
expect(result).toContain(`"scmPrice":${data.scmPrice}`)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "tf2wikipricing",
|
"name": "tf2wikipricing",
|
||||||
"version": "0.4.0",
|
"version": "0.4.1",
|
||||||
"description": "Adds item pricing to the Team Fortress 2 wiki",
|
"description": "Adds item pricing to the Team Fortress 2 wiki",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@happy-dom/global-registrator": "^17.4.4",
|
"@happy-dom/global-registrator": "^17.4.4",
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { findFirstElement, findFirstChildElement } from './utils/dom'
|
|||||||
import { extractPageTitleFromURL } from './utils/url';
|
import { extractPageTitleFromURL } from './utils/url';
|
||||||
var itemSchema: ItemSchema | null;
|
var itemSchema: ItemSchema | null;
|
||||||
|
|
||||||
var pageLocale: string = 'en'
|
var locale: string = 'en'
|
||||||
|
|
||||||
/** Exclude these from the pricelist. */
|
/** Exclude these from the pricelist. */
|
||||||
const excludedQualities = new Set([
|
const excludedQualities = new Set([
|
||||||
@@ -31,7 +31,6 @@ async function inject() {
|
|||||||
// Not an item page
|
// Not an item page
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const locale = extractLocaleFromURL(document.URL);
|
|
||||||
var itemIndex: number | null = null;
|
var itemIndex: number | null = null;
|
||||||
var itemName: string | null = null;
|
var itemName: string | null = null;
|
||||||
|
|
||||||
@@ -251,7 +250,7 @@ async function inject() {
|
|||||||
}).reverse().forEach((element) => {
|
}).reverse().forEach((element) => {
|
||||||
priceInfoboxHeadingRow.insertAdjacentElement('afterend', element.row);
|
priceInfoboxHeadingRow.insertAdjacentElement('afterend', element.row);
|
||||||
})
|
})
|
||||||
if(!updateTime) { updateTime = new Date() }
|
if(!updateTime || !(updateTime instanceof Date) || isNaN(+updateTime)) updateTime = new Date()
|
||||||
|
|
||||||
// Footer row
|
// Footer row
|
||||||
const row = document.createElement("tr");
|
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
|
wipeSchema(); // FIXME: ugly hack. requires additional page reload. if prepareSchema returns null, we should handle it properly
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pageLocale = extractLocaleFromURL(document.URL)
|
locale = extractLocaleFromURL(document.URL)
|
||||||
addStyles();
|
addStyles();
|
||||||
inject();
|
inject();
|
||||||
// TODO: Purge expired price data
|
// TODO: Purge expired price data
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import { logDebug, log } from "./utils/log"
|
|||||||
export class ItemPriceData {
|
export class ItemPriceData {
|
||||||
/** Item SKU. */
|
/** Item SKU. */
|
||||||
sku: string
|
sku: string
|
||||||
/** Date updated. */
|
/** Date updated, as Unix timestamp. */
|
||||||
update: Date
|
update: number
|
||||||
/** TTL in milliseconds. */
|
/** TTL in milliseconds. */
|
||||||
ttl: number
|
ttl: number
|
||||||
/** Price in keys. */
|
/** Price in keys. */
|
||||||
@@ -19,7 +19,7 @@ export class ItemPriceData {
|
|||||||
scmPrice: number
|
scmPrice: number
|
||||||
|
|
||||||
toString(): string {
|
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({
|
JSON.stringify({
|
||||||
keys: this.keys,
|
keys: this.keys,
|
||||||
metal: this.metal,
|
metal: this.metal,
|
||||||
@@ -43,8 +43,8 @@ export async function fetchPrice(token: string, sku: string, update: Date = new
|
|||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
var data: ItemPriceData | null
|
var data: ItemPriceData | null
|
||||||
|
|
||||||
const cached = await getStorageValue(storage_priceprefix + sku, null)
|
const cached: ItemPriceData = await getStorageValue(storage_priceprefix + sku, null)
|
||||||
if (cached != null && 'keys' in cached && 'metal' in cached) {
|
if (cached != null && 'keys' in cached && 'metal' in cached && !isNaN(cached.update)) {
|
||||||
data = cached
|
data = cached
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ export async function fetchPrice(token: string, sku: string, update: Date = new
|
|||||||
}
|
}
|
||||||
data = new ItemPriceData()
|
data = new ItemPriceData()
|
||||||
data.sku = sku
|
data.sku = sku
|
||||||
data.update = update
|
data.update = update.getTime()
|
||||||
data.ttl = ttl
|
data.ttl = ttl
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export function formatPrice(keys: number, metal: number, keyPrice: number, local
|
|||||||
if(keys > 0) {
|
if(keys > 0) {
|
||||||
output += (formattedKeys == 1.0 ? $T("%@ key") : $T("%@ keys")).replace('%@', formattedKeys.toLocaleString(locale))
|
output += (formattedKeys == 1.0 ? $T("%@ key") : $T("%@ keys")).replace('%@', formattedKeys.toLocaleString(locale))
|
||||||
} else {
|
} else {
|
||||||
output += `${(+toFixed(metal, 2)).toLocaleString(locale)} ref`
|
output += $T("%@ ref").replace('%@', (+toFixed(metal, 2)).toLocaleString(locale))
|
||||||
}
|
}
|
||||||
const currencyFormatter = new Intl.NumberFormat(locale, {
|
const currencyFormatter = new Intl.NumberFormat(locale, {
|
||||||
minimumFractionDigits: 2,
|
minimumFractionDigits: 2,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ module.exports = {
|
|||||||
|
|
||||||
// Price strings
|
// Price strings
|
||||||
"Data unavailable": "Data unavailable", // sourced from AppleGlot
|
"Data unavailable": "Data unavailable", // sourced from AppleGlot
|
||||||
|
"%@ ref": "%@ ref",
|
||||||
"%@ key": "%@ key",
|
"%@ key": "%@ key",
|
||||||
"%@ keys": "%@ keys",
|
"%@ keys": "%@ keys",
|
||||||
|
|
||||||
@@ -20,5 +21,6 @@ module.exports = {
|
|||||||
"Unique": "Unique",
|
"Unique": "Unique",
|
||||||
"Strange": "Strange",
|
"Strange": "Strange",
|
||||||
"Collector's": "Collector's",
|
"Collector's": "Collector's",
|
||||||
"Haunted": "Haunted"
|
"Haunted": "Haunted",
|
||||||
|
"Australium": "Australium"
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ module.exports = {
|
|||||||
|
|
||||||
// Price strings
|
// Price strings
|
||||||
"Data unavailable": "Datos no disponibles", // sourced from AppleGlot
|
"Data unavailable": "Datos no disponibles", // sourced from AppleGlot
|
||||||
|
"%@ ref": "%@ ref",
|
||||||
"%@ key": "%@ llave",
|
"%@ key": "%@ llave",
|
||||||
"%@ keys": "%@ llaves",
|
"%@ keys": "%@ llaves",
|
||||||
|
|
||||||
@@ -20,5 +21,6 @@ module.exports = {
|
|||||||
"Unique": "de Calidad Única",
|
"Unique": "de Calidad Única",
|
||||||
"Strange": "de Calidad Rara",
|
"Strange": "de Calidad Rara",
|
||||||
"Collector's": "de Coleccionista",
|
"Collector's": "de Coleccionista",
|
||||||
"Haunted": "de Calidad Embrujada"
|
"Haunted": "de Calidad Embrujada",
|
||||||
|
"Australium": "de Australium"
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,26 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
|
// Generic button text, %@ is always a URL (eg. backpack.tf)
|
||||||
"View listings on %@": "Voir les offres sur %@",
|
"View listings on %@": "Voir les offres sur %@",
|
||||||
|
|
||||||
|
// Itembox header
|
||||||
"Community Pricing": "Community Pricing",
|
"Community Pricing": "Community Pricing",
|
||||||
"Updated %@": "Updated %@",
|
// Itembox footer
|
||||||
"From %@": "From %@",
|
"Updated %@": "Updated %@.",
|
||||||
"Data unavailable": "Data unavailable",
|
"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",
|
"%@ key": "%@ key",
|
||||||
"%@ keys": "%@ keys",
|
"%@ keys": "%@ keys",
|
||||||
|
|
||||||
|
// Item quality names, all sourced from TF2 wiki
|
||||||
"Normal": "Normale",
|
"Normal": "Normale",
|
||||||
"Genuine": "Autentico",
|
"Genuine": "Autentico",
|
||||||
"Vintage": "Vintage",
|
"Vintage": "Vintage",
|
||||||
"Unique": "Unico",
|
"Unique": "Unico",
|
||||||
"Strange": "Strano",
|
"Strange": "Strano",
|
||||||
"Collector's": "Da collezione",
|
"Collector's": "Da collezione",
|
||||||
"Haunted": "Stregato"
|
"Haunted": "Stregato",
|
||||||
|
"Australium": "Australium"
|
||||||
}
|
}
|
||||||
@@ -10,8 +10,9 @@ module.exports = {
|
|||||||
|
|
||||||
// Price strings
|
// Price strings
|
||||||
"Data unavailable": "データがありません", // sourced from AppleGlot
|
"Data unavailable": "データがありません", // sourced from AppleGlot
|
||||||
"%@ key": "%@ key",
|
"%@ ref": "%@精錬メタル",
|
||||||
"%@ keys": "%@ keys",
|
"%@ key": "%@個の鍵",
|
||||||
|
"%@ keys": "%@個の鍵",
|
||||||
|
|
||||||
// Item quality names, all sourced from TF2 wiki
|
// Item quality names, all sourced from TF2 wiki
|
||||||
"Normal": "ノーマル",
|
"Normal": "ノーマル",
|
||||||
@@ -20,5 +21,6 @@ module.exports = {
|
|||||||
"Unique": "専用",
|
"Unique": "専用",
|
||||||
"Strange": "ストレンジ",
|
"Strange": "ストレンジ",
|
||||||
"Collector's": "Collector's",
|
"Collector's": "Collector's",
|
||||||
"Haunted": "Haunted"
|
"Haunted": "Haunted",
|
||||||
|
"Australium": "オーストラリウム"
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user