You've already forked tf2wikipricing
feat: schema now retrieves slot, australium status, killstreak status
This commit is contained in:
@@ -4,8 +4,13 @@ import './config'
|
||||
declare function GM_fetch(input: string | URL | globalThis.Request, init?: RequestInit): Promise<Response>
|
||||
import './GM_fetch'
|
||||
import { storage_version, storage_schema, storage_lastUpdateTime } from './config'
|
||||
import Australiums from '../resources/australiums.json'
|
||||
const semver = require('semver')
|
||||
|
||||
export function checkAustraliumVariant(defindex: number): boolean {
|
||||
return Object.prototype.hasOwnProperty.call(Australiums, defindex.toString());
|
||||
}
|
||||
|
||||
export declare const __VERSION__: string;
|
||||
|
||||
function isDateAfterOneDay(date1: Date, date2: Date): boolean {
|
||||
@@ -14,7 +19,28 @@ function isDateAfterOneDay(date1: Date, date2: Date): boolean {
|
||||
return diffDays > 1;
|
||||
}
|
||||
|
||||
export class ItemSchema { [key: string]: {name: string, tradable: Boolean}; }
|
||||
export enum ItemSlot {
|
||||
Primary = "primary",
|
||||
Secondary = "secondary",
|
||||
Melee = "melee",
|
||||
PDA = "pda",
|
||||
PDA2 = "pda2",
|
||||
Building = "building",
|
||||
Misc = "misc",
|
||||
Special = "special",
|
||||
Taunt = "taunt",
|
||||
Tool = "tool",
|
||||
}
|
||||
|
||||
export class ItemSchema {
|
||||
[key: string]: {
|
||||
name: string,
|
||||
slot: ItemSlot,
|
||||
tradable: Boolean,
|
||||
hasAustraliumVariant: Boolean,
|
||||
canKillstreakify: Boolean
|
||||
};
|
||||
}
|
||||
|
||||
export function getItemIndexByName(schema: ItemSchema, name: string, excludeStock: Boolean = true, excludeDecorated: Boolean = true) {
|
||||
for (const [defindex, value] of Object.entries(schema)) {
|
||||
@@ -63,6 +89,7 @@ export async function prepareSchema(): Promise<ItemSchema> {
|
||||
log(`Cache is from a previous version (${storedVersion}) of the extension. Updating for version ${__VERSION__}`);
|
||||
needsUpdate = true
|
||||
} else {
|
||||
log(`Cache is from current version (${storedVersion}) of the extension.`);
|
||||
itemSchema = await getStorageValue(storage_schema, null);
|
||||
}
|
||||
|
||||
@@ -87,8 +114,8 @@ export async function prepareSchema(): Promise<ItemSchema> {
|
||||
var responseItems: any[] = await response.json()
|
||||
// We want to keep the keys `defindex`, `item_name`, and `attributes`
|
||||
responseItems.forEach((item: any) => {
|
||||
const defindex = item['defindex']
|
||||
const name = item['item_name']
|
||||
const defindex: number = item['defindex']
|
||||
|
||||
var tradable: Boolean = true
|
||||
try {
|
||||
if(item['attributes'] != null) {
|
||||
@@ -100,7 +127,26 @@ export async function prepareSchema(): Promise<ItemSchema> {
|
||||
logError(error)
|
||||
log(item)
|
||||
}
|
||||
(cacheItems as any)[defindex.toString()] = { "name": name, "tradable": tradable }
|
||||
|
||||
var canKillstreakify: Boolean = false
|
||||
try {
|
||||
if(item['capabilities'] != null) {
|
||||
if(item['capabilities']['can_killstreakify'] != null && item['capabilities']['can_killstreakify'] == true) {
|
||||
canKillstreakify = true
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
logError(error)
|
||||
log(item)
|
||||
}
|
||||
|
||||
(cacheItems as any)[defindex.toString()] = {
|
||||
"name": item['item_name'],
|
||||
"slot": item['item_slot'],
|
||||
"tradable": tradable,
|
||||
"canKillstreakify": canKillstreakify,
|
||||
"hasAustraliumVariant": checkAustraliumVariant(defindex)
|
||||
}
|
||||
});
|
||||
|
||||
await setStorageValue(storage_schema, (cacheItems));
|
||||
|
||||
Reference in New Issue
Block a user