diff --git a/manifest.json b/manifest.json index 352960e..a818d59 100644 --- a/manifest.json +++ b/manifest.json @@ -11,13 +11,13 @@ }, "content_scripts": [ { - "matches": ["https://csfloat.com/*", "https://csgofloat.com/*"], + "matches": ["*://*.csfloat.com/*", "*://*.csgofloat.com/*"], "js": ["js/content_script.js"], "css": ["css/stylesheet.css"], - "run_at": "document_idle" + "run_at": "document_end" }, { - "matches": ["https://csfloat.com/*", "https://csgofloat.com/*"], + "matches": ["*://*.csfloat.com/*", "*://*.csgofloat.com/*"], "js": ["js/injectionhandler.js"], "run_at": "document_start" } diff --git a/src/content_script.ts b/src/content_script.ts index 7084f6d..b2e530a 100644 --- a/src/content_script.ts +++ b/src/content_script.ts @@ -2,7 +2,17 @@ import { ExtensionSettings, FloatItem, HistoryData, ItemCondition, ItemStyle, ListingData } from './@typings/FloatTypes'; import { activateHandler } from './eventhandler'; -import { getBuffMapping, getInventoryHelperPrice, getFirstCachedItem, getItemPrice, getPriceMapping, getWholeHistory, handleSpecialStickerNames, loadBuffMapping, loadMapping } from './mappinghandler'; +import { + getBuffMapping, + getInventoryHelperPrice, + getFirstCachedItem, + getItemPrice, + getPriceMapping, + getWholeHistory, + handleSpecialStickerNames, + loadBuffMapping, + loadMapping, +} from './mappinghandler'; type PriceResult = { price_difference: number; @@ -18,35 +28,34 @@ async function init() { // this has to be done as first thing to not miss timed events activateHandler(); - // mutation observer is only needed once - if (!isObserverActive) { - console.debug('[BetterFloat] Starting observer'); - await applyMutation(); - console.log('[BetterFloat] Observer started'); - - isObserverActive = true; - } - await initSettings(); + await loadMapping(); + await loadBuffMapping(); if (extensionSettings.showTopButton) { createTopButton(); } + //check if url is in supported subpages if (url.endsWith('float.com/')) { await firstLaunch(); - return; } else { for (let i = 0; i < supportedSubPages.length; i++) { if (url.includes(supportedSubPages[i])) { - console.debug('[BetterFloat] Current page supported'); await firstLaunch(); - return; } } } - console.debug('[BetterFloat] Current page not supported: ' + url); + + // mutation observer is only needed once + if (!isObserverActive) { + console.debug('[BetterFloat] Starting observer'); + await applyMutation(); + console.log('[BetterFloat] Observer started'); + + isObserverActive = true; + } } // required as mutation does not detect initial DOM @@ -240,8 +249,6 @@ async function applyMutation() { await refreshButton(); } }); - await loadMapping(); - await loadBuffMapping(); observer.observe(document, { childList: true, subtree: true }); } diff --git a/src/mappinghandler.ts b/src/mappinghandler.ts index bd19cea..7378d1b 100644 --- a/src/mappinghandler.ts +++ b/src/mappinghandler.ts @@ -114,7 +114,7 @@ export async function getInventoryHelperPrice(buff_name: string): Promise response.json()).then((data: SteaminventoryhelperResponse) => { + console.log(`[BetterFloat] Steaminventoryhelper response for ${buff_name}: `, data); cachedInventoryHelperResponses[buff_name] = data; return data?.items[buff_name]?.buff163?.price; - } else { - console.log(`[BetterFloat] Steaminventoryhelper did not return success for ${buff_name}`); - cachedInventoryHelperResponses[buff_name] = null; + }).catch((err) => { + console.error(err); return null; - } + }); } export async function getBuffMapping(name: string) { diff --git a/webpack/webpack.dev.js b/webpack/webpack.dev.js index 2872e95..80d67ce 100644 --- a/webpack/webpack.dev.js +++ b/webpack/webpack.dev.js @@ -2,7 +2,7 @@ const { merge } = require('webpack-merge'); const common = require('./webpack.common.js'); module.exports = merge(common, { - //mode: 'development', - //devtool: 'inline-source-map', + // mode: 'development', + // devtool: 'inline-source-map', mode: 'production', }); \ No newline at end of file