Skip to content

Commit

Permalink
Market Comparison feature
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Feb 22, 2025
1 parent df4830a commit 7f11b45
Show file tree
Hide file tree
Showing 20 changed files with 425 additions and 96 deletions.
6 changes: 6 additions & 0 deletions assets/logos/skinbid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/screenshots/youpin-buyorder-example.png
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "betterfloat",
"displayName": "BetterFloat",
"version": "3.0.16",
"version": "3.1.0",
"description": "Enhance your website experience on 9+ CS2 skin markets!",
"author": "Rums",
"license": "CC BY NC SA 4.0",
Expand Down
3 changes: 2 additions & 1 deletion src/contents/csfloat_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1622,7 +1622,8 @@ async function addBuffPrice(
source === MarketSource.Steam ||
(source === MarketSource.C5Game && priceListing) ||
(source === MarketSource.YouPin && priceListing) ||
(source === MarketSource.CSFloat && priceListing);
(source === MarketSource.CSFloat && priceListing) ||
(source === MarketSource.CSMoney && priceListing);

if (priceContainer && !container.querySelector('.betterfloat-buffprice') && popout !== POPOUT_ITEM.SIMILAR && itemExists) {
const buffContainer = generatePriceLine({
Expand Down
29 changes: 5 additions & 24 deletions src/contents/skinbid_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Decimal from 'decimal.js';

import { activateHandler, initPriceMapping } from '~lib/handlers/eventhandler';
import { getItemPrice, getMarketID, loadMapping } from '~lib/handlers/mappinghandler';
import { ICON_ARROWUP_SMALL, ICON_BUFF, ICON_C5GAME, ICON_CAMERA, ICON_CLOCK, ICON_CSFLOAT, ICON_STEAM, ICON_YOUPIN, MarketSource } from '~lib/util/globals';
import { AvailableMarketSources, ICON_ARROWUP_SMALL, ICON_BUFF, ICON_CAMERA, ICON_CLOCK, ICON_CSFLOAT, MarketSource } from '~lib/util/globals';
import {
CurrencyFormatter,
calculateEpochFromDate,
Expand Down Expand Up @@ -604,39 +604,20 @@ function generateBuffContainer(
source: MarketSource,
isItemPage = false
) {
let icon = '';
let iconStyle = 'height: 20px; margin-right: 5px;';
let containerStyle = '';
if (source === MarketSource.Buff) {
icon = ICON_BUFF;
iconStyle += 'border: 1px solid #323c47;';
} else if (source === MarketSource.Steam) {
icon = ICON_STEAM;
} else if (source === MarketSource.C5Game) {
icon = ICON_C5GAME;
iconStyle += 'border: 1px solid #323c47;';
containerStyle = 'justify-content: flex-start;';
} else if (source === MarketSource.YouPin) {
icon = ICON_YOUPIN;
iconStyle += 'border: 1px solid #323c47;';
containerStyle = 'justify-content: flex-start;';
} else if (source === MarketSource.CSFloat) {
icon = ICON_CSFLOAT;
iconStyle += 'border: 1px solid #323c47;';
containerStyle = 'justify-content: flex-start;';
}
const { logo: icon, style: iconStyle } = AvailableMarketSources.find((s) => s.source === source) ?? { logo: '', style: '' };
const containerStyle = priceListing && priceOrder ? '' : 'justify-content: flex-start;';
const formatter = CurrencyFormatter(currencyText);
const buffContainer = html`
<a class="betterfloat-buff-container" target="_blank" href="${href}" style="display: flex; margin: 5px 0; cursor: pointer; align-items: center;">
${
isItemPage
? html`
<div style="display: flex; align-items: center; gap: 4px; width: 50%">
<img src="${icon}" style="${iconStyle}" />
<img src="${icon}" style="height: 20px; margin-right: 5px; ${iconStyle}" />
<span style="font-size: 14px; font-weight: 700; color: #a3a3cb;">${toTitleCase(source)}</span>
</div>
`
: html`<img src="${icon}" style="${iconStyle}" />`
: html`<img src="${icon}" style="height: 20px; margin-right: 5px; ${iconStyle}" />`
}
<div class="suggested-price betterfloat-buffprice" style="height: 100%; margin: 0; line-height: 1; align-items: center; ${isItemPage ? 'width: 50%;' : ''}${containerStyle}">
${
Expand Down
29 changes: 3 additions & 26 deletions src/contents/skinport_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import Decimal from 'decimal.js';
import { dynamicUIHandler, mountSpItemPageBuffContainer } from '~lib/handlers/urlhandler';
import { addPattern, createLiveLink, filterDisplay } from '~lib/helpers/skinport_helpers';
import {
AvailableMarketSources,
ICON_ARROWUP_SMALL,
ICON_BUFF,
ICON_C5GAME,
ICON_CAMERA,
ICON_CAMERA_FLIPPED,
ICON_CSFLOAT,
ICON_CSGOSTASH,
ICON_EXCLAMATION,
ICON_PRICEMPIRE,
ICON_STEAM,
ICON_STEAMANALYST,
ICON_YOUPIN,
MarketSource,
} from '~lib/util/globals';
import { CurrencyFormatter, checkUserPlanPro, delay, getBuffPrice, getFloatColoring, getMarketURL, isBuffBannedItem, isUserPro, toTitleCase, waitForElement } from '~lib/util/helperfunctions';
Expand Down Expand Up @@ -940,34 +938,13 @@ function convertCurrency(price: Decimal, currencyRate: number, settingRate: stri

function generateBuffContainer(container: HTMLElement, priceListing: Decimal | undefined, priceOrder: Decimal | undefined, currencySymbol: string, source: MarketSource, containerIsParent = false) {
const CurrencyFormatter = new Intl.NumberFormat(undefined, { style: 'currency', currency: currencySymbol, currencyDisplay: 'narrowSymbol', minimumFractionDigits: 0, maximumFractionDigits: 2 });
let icon = '';
let iconStyle = 'height: 22px; margin-right: 5px; border-radius: 5px;';
switch (source) {
case MarketSource.Buff:
icon = ICON_BUFF;
iconStyle += 'border: 1px solid #323c47;';
break;
case MarketSource.Steam:
icon = ICON_STEAM;
break;
case MarketSource.C5Game:
icon = ICON_C5GAME;
iconStyle += 'border: 1px solid #323c47;';
break;
case MarketSource.YouPin:
icon = ICON_YOUPIN;
iconStyle += 'border: 1px solid #323c47;';
break;
case MarketSource.CSFloat:
icon = ICON_CSFLOAT;
break;
}
const { logo: icon, style: iconStyle } = AvailableMarketSources.find((s) => s.source === source) ?? { logo: '', style: '' };

const showBothPrices = [MarketSource.Buff, MarketSource.Steam].includes(source) || (MarketSource.YouPin === source && isUserPro(extensionSettings['user']));

const buffContainer = html`
<div class="betterfloat-buff-container" style="display: flex; margin-top: 5px; align-items: center;">
<img src="${icon}" style="${iconStyle}" />
<img src="${icon}" style="height: 22px; margin-right: 5px; border-radius: 5px; ${iconStyle}" />
<div class="suggested-price betterfloat-buffprice" data-betterfloat="${JSON.stringify({ priceListing, priceOrder, currencySymbol })}">
${
showBothPrices
Expand Down
1 change: 1 addition & 0 deletions src/css/csfloat_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ body.light-theme {
display: inline-flex;
align-items: center;
font-size: 15px;
width: fit-content;
}

.betterfloat-sale-tag {
Expand Down
5 changes: 3 additions & 2 deletions src/lib/handlers/mappinghandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const priceMapping: {
c5game: Extension.PriceMappingMisc;
steam: Extension.PriceMappingSteam;
csfloat: Extension.PriceMappingMisc;
} = { buff: {}, youpin: {}, c5game: {}, steam: {}, csfloat: {} };
csmoney: Extension.PriceMappingMisc;
} = { buff: {}, youpin: {}, c5game: {}, steam: {}, csfloat: {}, csmoney: {} };
// crimson web mapping
let crimsonWebMapping: Extension.CrimsonWebMapping | null = null;

Expand Down Expand Up @@ -104,7 +105,7 @@ export function getMarketID(name: string, source: MarketSource) {
case MarketSource.C5Game:
return 'c5';
default:
// csfloat can be queried via buff name
// other markets can be queried via buff name
return null;
}
};
Expand Down
31 changes: 30 additions & 1 deletion src/lib/handlers/urlhandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { CSFloatHelpers } from '~lib/helpers/csfloat_helpers';
import { createLiveLink, filterDisplay } from '~lib/helpers/skinport_helpers';
import CSFAutorefresh from '~lib/inline/CSFAutorefresh';
import CSFBargainButtons from '~lib/inline/CSFBargainButtons';
import CSFMarketComparison from '~lib/inline/CSFMarketComparison';
import CSFMenuControl from '~lib/inline/CSFMenuControl';
import CSFQuickMenu from '~lib/inline/CSFQuickMenu';
import CSFThemeToggle from '~lib/inline/CSFThemeToggle';
Expand Down Expand Up @@ -73,7 +74,7 @@ export function dynamicUIHandler() {
await handleChange(state);
}, 1500);

// setTimeout(showUpdatePopup, 3000);
setTimeout(showUpdatePopup, 3000);
}

async function showUpdatePopup() {
Expand Down Expand Up @@ -151,6 +152,34 @@ async function handleCSFloatChange(state: Extension.URLState) {
}
}

const showMarketComparison = await ExtensionStorage.sync.get<boolean>('csf-marketcomparison');
if (showMarketComparison && state.path.includes('/item/') && !document.querySelector('betterfloat-market-comparison')) {
const success = await waitForElement('div.full-screen-dialog .container');
if (!success) return;
const popup = document.querySelector<HTMLElement>('div.full-screen-dialog');
const container = popup?.querySelector<HTMLElement>('.container');
if (popup && container) {
popup.style.width = Number(popup.style.width.substring(0, popup.style.width.length - 2)) + 230 + 'px';
container.style.gridTemplateColumns = '250px 1fr 210px 210px';
const root = await mountShadowRoot(<CSFMarketComparison />, {
tagName: 'betterfloat-market-comparison',
parent: container,
});
const ownContainer = document.querySelector<HTMLElement>('betterfloat-market-comparison');
if (ownContainer) {
ownContainer.style.gridRow = '1 / span 2';
}
// unmount on url change
const interval = createUrlListener((url) => {
if (!url.pathname.includes('/item/')) {
root.unmount();
document.querySelector('betterfloat-market-comparison')?.remove();
clearInterval(interval);
}
}, 1000);
}
}

const csfShowThemeToggle = await getSetting<boolean>('csf-themetoggle');
if (csfShowThemeToggle && !document.querySelector('betterfloat-theme-toggle')) {
const root = await mountShadowRoot(<CSFThemeToggle />, {
Expand Down
Loading

0 comments on commit 7f11b45

Please sign in to comment.