You've already forked tf2wikipricing
lint: var to let/const
This commit is contained in:
@@ -10,10 +10,10 @@ import { createPriceRow, createStoreButton } from './uiRenderer'
|
||||
import { findFirstElement, findFirstChildElement } from './utils/dom'
|
||||
import { extractPageTitleFromURL } from './utils/url';
|
||||
import { ExchangeRates, prepareExchangeRates } from './exchangeRateService';
|
||||
var itemSchema: ItemSchema | null;
|
||||
var exchangeRates: ExchangeRates | null;
|
||||
let itemSchema: ItemSchema | null;
|
||||
let exchangeRates: ExchangeRates | null;
|
||||
|
||||
var locale: string = 'en'
|
||||
let locale: string = 'en'
|
||||
|
||||
/** Exclude these from the pricelist. */
|
||||
const excludedQualities = new Set([
|
||||
@@ -33,8 +33,8 @@ async function inject() {
|
||||
// Not an item page
|
||||
return;
|
||||
}
|
||||
var itemIndex: number | null = null;
|
||||
var itemName: string | null = null;
|
||||
let itemIndex: number | null = null;
|
||||
let itemName: string | null = null;
|
||||
|
||||
// Find buy buttons
|
||||
const buyButton = findFirstChildElement('.btn_buynow', itemInfobox);
|
||||
@@ -94,7 +94,7 @@ async function inject() {
|
||||
return;
|
||||
}
|
||||
|
||||
var qualities: number[] = []
|
||||
const qualities: number[] = []
|
||||
|
||||
const firstQualityTag = findFirstChildElement('.quality-tag', itemInfobox);
|
||||
|
||||
@@ -122,7 +122,7 @@ async function inject() {
|
||||
// th.infobox-header (Basic Information)
|
||||
// ...
|
||||
|
||||
var storeButtons: HTMLTableRowElement[] = [];
|
||||
const storeButtons: HTMLTableRowElement[] = [];
|
||||
|
||||
// backpack.tf button
|
||||
storeButtons.push(createStoreButton("backpack.tf", new URL(`https://backpack.tf/classifieds?item=${encodeURIComponent(itemName)}`)));
|
||||
@@ -171,7 +171,7 @@ async function inject() {
|
||||
priceProgressRow.appendChild(priceProgressData);
|
||||
priceInfoboxHeadingRow.insertAdjacentElement('afterend', priceProgressRow);
|
||||
|
||||
var token: string | null;
|
||||
let token: string | null;
|
||||
|
||||
// Steam Community Market
|
||||
// TODO: Change this to lazy-load, so that it doesn't make network requests when we have cached data.
|
||||
@@ -187,7 +187,7 @@ async function inject() {
|
||||
log('Failed to get an access token for prices.tf: ' + err);
|
||||
}
|
||||
|
||||
var updateTime: Date | null = null;
|
||||
let updateTime: Date | null = null;
|
||||
|
||||
enum PriceRowCategory {
|
||||
None,
|
||||
@@ -201,19 +201,19 @@ async function inject() {
|
||||
row: HTMLTableRowElement
|
||||
category: PriceRowCategory
|
||||
}
|
||||
var priceRows: PriceRow[]= [];
|
||||
const priceRows: PriceRow[]= [];
|
||||
|
||||
// Get current key price
|
||||
const keyPrice = await fetchKeyPrice(token);
|
||||
|
||||
var currentTime = new Date()
|
||||
const currentTime = new Date()
|
||||
|
||||
const promises = qualities.filter(x => !excludedQualities.has(x)).map(async (quality) => {
|
||||
|
||||
const qualifiedName = ((quality != 6 ? itemQualities[quality as unknown as keyof typeof itemQualities].toString() : '') + ' ' + itemName).trim()
|
||||
// logDebug(`Fetching price for ${qualifiedName}`)
|
||||
|
||||
var data: ItemPriceData | null
|
||||
let data: ItemPriceData | null
|
||||
try {
|
||||
data = await fetchPrice(token, itemIndex + ";" + quality, currentTime);
|
||||
updateTime = new Date(data.update)
|
||||
@@ -231,7 +231,7 @@ async function inject() {
|
||||
if(itemSchema[itemIndex].hasAustraliumVariant) {
|
||||
promises.push(new Promise(async (resolve) => {
|
||||
logDebug(`Fetching price for Australium ${itemName}`)
|
||||
var data: ItemPriceData | null
|
||||
let data: ItemPriceData | null
|
||||
try {
|
||||
data = await fetchPrice(token, `${itemIndex};11;australium`, currentTime);
|
||||
updateTime = new Date(data.update)
|
||||
@@ -247,7 +247,7 @@ async function inject() {
|
||||
}))
|
||||
}
|
||||
|
||||
var festiveHeadingRow: HTMLTableRowElement | null
|
||||
let festiveHeadingRow: HTMLTableRowElement | null
|
||||
// Check item schema for Festive variant of current defindex
|
||||
if(itemSchema[itemIndex].festiveVariant != null) {
|
||||
/// Create subheading
|
||||
@@ -263,7 +263,7 @@ async function inject() {
|
||||
|
||||
promises.push(new Promise(async (resolve) => {
|
||||
logDebug(`Fetching price for Festive ${itemName}`)
|
||||
var data: ItemPriceData | null
|
||||
let data: ItemPriceData | null
|
||||
try {
|
||||
data = await fetchPrice(token, `${itemSchema[itemIndex].festiveVariant};6`, currentTime);
|
||||
updateTime = new Date(data.update)
|
||||
@@ -279,7 +279,7 @@ async function inject() {
|
||||
}))
|
||||
promises.push(new Promise(async (resolve) => {
|
||||
logDebug(`Fetching price for Strange Festive ${itemName}`)
|
||||
var data: ItemPriceData | null
|
||||
let data: ItemPriceData | null
|
||||
try {
|
||||
data = await fetchPrice(token, `${itemSchema[itemIndex].festiveVariant};11`, currentTime);
|
||||
updateTime = new Date(data.update)
|
||||
@@ -295,7 +295,7 @@ async function inject() {
|
||||
}))
|
||||
}
|
||||
|
||||
var killstreakKitHeadingRow: HTMLTableRowElement | null
|
||||
let killstreakKitHeadingRow: HTMLTableRowElement | null
|
||||
// Check for Killstreak Kits
|
||||
if(itemSchema[itemIndex].slot == ItemSlot.Primary ||
|
||||
itemSchema[itemIndex].slot == ItemSlot.Secondary ||
|
||||
@@ -314,9 +314,9 @@ async function inject() {
|
||||
[1,2,3].map((tier) => {
|
||||
promises.push(new Promise(async (resolve) => {
|
||||
logDebug(`Fetching price for ${itemName} Killstreak Kit Tier ${tier}`)
|
||||
var data: ItemPriceData | null
|
||||
let data: ItemPriceData | null
|
||||
try {
|
||||
var kitIndex: number
|
||||
let kitIndex: number
|
||||
switch (tier) {
|
||||
default:
|
||||
case 1: kitIndex = 6527; break;
|
||||
@@ -351,7 +351,7 @@ async function inject() {
|
||||
"Silver Mk.II",
|
||||
"Gold Mk.II",
|
||||
]
|
||||
var botKillerHeadingRow: HTMLTableRowElement | null
|
||||
let botKillerHeadingRow: HTMLTableRowElement | null
|
||||
if(itemSchema[itemIndex].botkillerVariants != null && itemSchema[itemIndex].botkillerVariants.length > 0) {
|
||||
/// Create subheading
|
||||
botKillerHeadingRow = document.createElement("tr")
|
||||
@@ -370,7 +370,7 @@ async function inject() {
|
||||
const variantName = itemName.includes('Mk.II') ? itemName.split(' ')[0] + ' Mk.II' : itemName.split(' ')[0]
|
||||
promises.push(new Promise(async (resolve) => {
|
||||
logDebug(`Fetching price for ${itemName}`)
|
||||
var data: ItemPriceData | null
|
||||
let data: ItemPriceData | null
|
||||
try {
|
||||
data = await fetchPrice(token, `${variantIndex};11`, currentTime);
|
||||
updateTime = new Date(data.update)
|
||||
|
||||
@@ -16,8 +16,8 @@ export async function wipeExchangeRates(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function prepareExchangeRates(): Promise<ExchangeRates> {
|
||||
var needsUpdate: Boolean = false
|
||||
var rates: ExchangeRates | null = null
|
||||
let needsUpdate: boolean = false
|
||||
let rates: ExchangeRates | null = null
|
||||
|
||||
rates = await getStorageValue(storage_exchangerates, null);
|
||||
const update = await getStorageValue(storage_exchangerates_update, null)
|
||||
@@ -39,7 +39,7 @@ export async function prepareExchangeRates(): Promise<ExchangeRates> {
|
||||
const response = await GM_fetch(url);
|
||||
if (response.ok) {
|
||||
await setStorageValue(storage_exchangerates_update, new Date().toISOString())
|
||||
var json = await response.json()
|
||||
const json = await response.json()
|
||||
if(json != null){
|
||||
rates = json['rates']
|
||||
await setStorageValue(storage_exchangerates, rates)
|
||||
|
||||
@@ -41,7 +41,7 @@ export async function fetchKeyPrice(token: string) {
|
||||
*/
|
||||
export async function fetchPrice(token: string, sku: string, update: Date = new Date(), ttl: number = 30 * 60 * 1000): Promise<ItemPriceData> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
var data: ItemPriceData | null
|
||||
let data: ItemPriceData | null
|
||||
|
||||
const cached: ItemPriceData = await getStorageValue(storage_priceprefix + sku, null)
|
||||
if (cached != null && 'keys' in cached && 'metal' in cached && !isNaN(cached.update)) {
|
||||
|
||||
@@ -46,7 +46,7 @@ async function priceUsingPricesTF(token: string, sku: string, retries: number =
|
||||
if (!token) {
|
||||
reject(401)
|
||||
}
|
||||
var response = await GM_fetch(`https://api2.prices.tf/prices/${encodeURIComponent(sku)}`, {
|
||||
let response = await GM_fetch(`https://api2.prices.tf/prices/${encodeURIComponent(sku)}`, {
|
||||
method: 'get',
|
||||
headers: new Headers({
|
||||
'Accept': 'application/json',
|
||||
|
||||
@@ -14,8 +14,8 @@ export function checkAustraliumVariant(defindex: number): boolean {
|
||||
export declare const __VERSION__: string;
|
||||
|
||||
function isDateAfterOneDay(date1: Date, date2: Date): boolean {
|
||||
var diff = date2.getTime() - date1.getTime();
|
||||
var diffDays = Math.round(diff / (1000 * 3600 * 24));
|
||||
const diff = date2.getTime() - date1.getTime();
|
||||
const diffDays = Math.round(diff / (1000 * 3600 * 24));
|
||||
return diffDays > 1;
|
||||
}
|
||||
|
||||
@@ -119,8 +119,8 @@ export async function wipeSchema(): Promise<void> {
|
||||
}
|
||||
|
||||
export async function prepareSchema(): Promise<ItemSchema> {
|
||||
var needsUpdate: Boolean = false
|
||||
var itemSchema: ItemSchema | null = null
|
||||
let needsUpdate: boolean = false
|
||||
let itemSchema: ItemSchema | null = null
|
||||
|
||||
const storedVersion: string | null = await getStorageValue(storage_version, null)
|
||||
if(!storedVersion || !semver.valid(storedVersion)) {
|
||||
@@ -150,14 +150,14 @@ export async function prepareSchema(): Promise<ItemSchema> {
|
||||
if (response.ok) {
|
||||
await setStorageValue(storage_lastUpdateTime, new Date().getTime());
|
||||
|
||||
var cacheItems = {}
|
||||
const cacheItems = {}
|
||||
|
||||
var responseItems: any[] = await response.json()
|
||||
const responseItems: any[] = await response.json()
|
||||
// We want to keep the keys `defindex`, `item_name`, and `attributes`
|
||||
responseItems.forEach((item: any) => {
|
||||
const defindex: number = item['defindex']
|
||||
|
||||
var tradable: Boolean = true
|
||||
let tradable: boolean = true
|
||||
try {
|
||||
if(item['attributes'] != null) {
|
||||
if(item['attributes'].find((attribute: {}) => (attribute as any)['class'] == "cannot_trade")) {
|
||||
@@ -169,7 +169,7 @@ export async function prepareSchema(): Promise<ItemSchema> {
|
||||
log(item)
|
||||
}
|
||||
|
||||
var canKillstreakify: Boolean = false
|
||||
let canKillstreakify: boolean = false
|
||||
try {
|
||||
if(item['capabilities'] != null) {
|
||||
if(item['capabilities']['can_killstreakify'] != null && item['capabilities']['can_killstreakify'] == true) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
declare var __ENV_USERSCRIPT: boolean;
|
||||
declare var __ENV_WEBEXTENSION: boolean;
|
||||
declare let __ENV_USERSCRIPT: boolean;
|
||||
declare let __ENV_WEBEXTENSION: boolean;
|
||||
|
||||
function getStorageValue(name: string, defaultValue: string): Promise<any> {
|
||||
if(__ENV_USERSCRIPT) {
|
||||
|
||||
@@ -22,14 +22,14 @@ export function createPriceRow(qualityName: string, data: ItemPriceData, keyPric
|
||||
|
||||
const priceData = document.createElement("td");
|
||||
const priceLink = document.createElement("span");
|
||||
var priceString: string = ''
|
||||
let priceString: string = ''
|
||||
|
||||
if(data) {
|
||||
const gamePrice = formatPrice(data.keys, data.metal, keyPrice.metal, locale).trim()
|
||||
const realPriceUSD = convertTF2PriceToUSD(data.keys, data.metal, keyPrice.metal)
|
||||
|
||||
const USDFormatter = new Intl.NumberFormat(locale, { style: "currency", currency: 'USD' })
|
||||
var realPriceString = USDFormatter.format(realPriceUSD)
|
||||
let realPriceString = USDFormatter.format(realPriceUSD)
|
||||
const currency = defaultCurrencyForPageLocale(locale) ?? 'USD'
|
||||
if(currency !== 'USD') {
|
||||
try {
|
||||
@@ -56,7 +56,7 @@ export function createPriceRow(qualityName: string, data: ItemPriceData, keyPric
|
||||
|
||||
export function createStoreButton(storeName: string, url: URL) {
|
||||
const button = document.createElement("tr")
|
||||
var source = `<td colspan="2" class="infobox-data" style="text-align:center"><div class="plainlinks btn_wrapper" style="width:100%"><a rel="nofollow" class="external text" href="{link}" target="_blank"><span class="btn_buynow_addon_${storeName.replaceAll('.', '')}">{title}<span></span></span></a></div></td>`
|
||||
let source = `<td colspan="2" class="infobox-data" style="text-align:center"><div class="plainlinks btn_wrapper" style="width:100%"><a rel="nofollow" class="external text" href="{link}" target="_blank"><span class="btn_buynow_addon_${storeName.replaceAll('.', '')}">{title}<span></span></span></a></div></td>`
|
||||
source = source.replace("{link}", url.toString())
|
||||
source = source.replace("{title}", $T("View listings on %@").replace('%@', storeName))
|
||||
button.innerHTML = source
|
||||
|
||||
@@ -2,14 +2,14 @@ import { conversion_ref_usd } from '../config';
|
||||
import { $T } from './localization'
|
||||
|
||||
function toFixed(num: number, fixed: number) {
|
||||
var re = new RegExp('^-?\\d+(?:\.\\d{0,' + (fixed || -1) + '})?');
|
||||
const re = new RegExp('^-?\\d+(?:\.\\d{0,' + (fixed || -1) + '})?');
|
||||
return num.toString().match(re)[0];
|
||||
}
|
||||
|
||||
export function formatPrice(keys: number, metal: number, keyPrice: number, locale: string = 'en') {
|
||||
const formattedKeys = +(keys + (metal / keyPrice)).toFixed(2)
|
||||
|
||||
var output: string = ''
|
||||
let output: string = ''
|
||||
if(keys > 0) {
|
||||
output += (formattedKeys == 1.0 ? $T("%@ key") : $T("%@ keys")).replace('%@', formattedKeys.toLocaleString(locale))
|
||||
} else {
|
||||
|
||||
@@ -30,7 +30,7 @@ export function $T(s: string, locale?: Intl.LocalesArgument): string {
|
||||
}
|
||||
|
||||
export function extractLocaleFromURL(url: string): string {
|
||||
var split = url.substring(url.indexOf("/wiki/") + "/wiki/".length);
|
||||
const split = url.substring(url.indexOf("/wiki/") + "/wiki/".length);
|
||||
if (split.indexOf('/') != -1) {
|
||||
// Remove language suffix e.g. `/es`
|
||||
return split.substring(split.indexOf('/') + 1);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
declare var __PRODUCTION: boolean;
|
||||
declare var __EXTENSION_NAME: string;
|
||||
declare let __EXTENSION_NAME: string;
|
||||
const logHeader = `[${__EXTENSION_NAME}] `;
|
||||
|
||||
/** `console.debug` with header; automatically NO-OP on production build */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export function extractPageTitleFromURL(url: string): string {
|
||||
var split = url.substring(url.indexOf("/wiki/") + "/wiki/".length);
|
||||
let split = url.substring(url.indexOf("/wiki/") + "/wiki/".length);
|
||||
if (split.indexOf('/') != -1) {
|
||||
// Remove language suffix (/es)
|
||||
split = split.substring(0, split.indexOf('/'));
|
||||
|
||||
Reference in New Issue
Block a user