Skip to content

Commit

Permalink
Fix of double pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Aug 26, 2023
1 parent 306f689 commit bf6fa55
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
39 changes: 23 additions & 16 deletions src/content_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -240,8 +249,6 @@ async function applyMutation() {
await refreshButton();
}
});
await loadMapping();
await loadBuffMapping();
observer.observe(document, { childList: true, subtree: true });
}

Expand Down
15 changes: 6 additions & 9 deletions src/mappinghandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export async function getInventoryHelperPrice(buff_name: string): Promise<number
return cachedInventoryHelperResponses[buff_name]?.items[buff_name]?.buff163?.price ?? null;
}
console.log(`[BetterFloat] Attempting to get price for ${buff_name} from steaminventoryhelper`);
const reponse = await fetch('https://api.steaminventoryhelper.com/v2/live-prices/getPrices', {
return await fetch('https://api.steaminventoryhelper.com/v2/live-prices/getPrices', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -124,17 +124,14 @@ export async function getInventoryHelperPrice(buff_name: string): Promise<number
markets: ['buff163'],
items: [buff_name],
}),
});
const data: SteaminventoryhelperResponse = await reponse.json();
console.log(`[BetterFloat] Steaminventoryhelper response for ${buff_name}: `, data);
if (data.success) {
}).then((response) => 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) {
Expand Down
4 changes: 2 additions & 2 deletions webpack/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

0 comments on commit bf6fa55

Please sign in to comment.