Skip to content

Commit

Permalink
fix: csfloat links for prices
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Jan 1, 2025
1 parent 5dfb443 commit bfe33ad
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
17 changes: 4 additions & 13 deletions src/contents/skinport_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,24 +296,15 @@ async function adjustItemPage(container: Element) {
const market_id = getMarketID(buffItem.buff_name, buffItem.source);
const isDoppler = item.name.includes('Doppler') && (item.category === 'Knife' || item.category === 'Weapon');

const href = getMarketURL({ source: buffItem.source, buff_name: buffItem.buff_name, market_id, phase: isDoppler ? (item.style as DopplerPhase) : undefined });
const link = getMarketURL({ source: buffItem.source, buff_name: buffItem.buff_name, market_id, phase: isDoppler ? (item.style as DopplerPhase) : undefined });

container.setAttribute('data-betterfloat', JSON.stringify({ itemPrice: item.price, currency: item.currency, buff_id: market_id, ...buffItem }));
container.setAttribute('data-betterfloat', JSON.stringify({ itemPrice: item.price, currency: item.currency, buff_id: market_id, link, ...buffItem }));

const suggestedContainer = container.querySelector('.ItemPage-suggested');
if (suggestedContainer) {
await mountSpItemPageBuffContainer();
}

const buffContainer = container.querySelector('.betterfloat-buff-container');
if (buffContainer) {
(<HTMLElement>buffContainer).onclick = (e: Event) => {
e.stopPropagation();
e.preventDefault();
window.open(href, '_blank');
};
}

const priceFromReference = [MarketSource.Buff, MarketSource.Steam].includes(buffItem.source) && extensionSettings['sp-pricereference'] === 0 ? buffItem.priceOrder : buffItem.priceListing;
const difference = new Decimal(item.price).minus(priceFromReference ?? 0);
const priceContainer = <HTMLElement>container.querySelector('.ItemPage-price');
Expand Down Expand Up @@ -966,11 +957,11 @@ async function addBuffPrice(item: Skinport.Listing, container: Element) {
} else {
const buffContainer = container.querySelector('.betterfloat-buff-container');
if (buffContainer) {
(<HTMLElement>buffContainer).onclick = (e: Event) => {
buffContainer.addEventListener('click', (e) => {
e.stopPropagation();
e.preventDefault();
window.open(href, '_blank');
};
});
}
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/handlers/mappinghandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export function getMarketID(name: string, source: MarketSource) {
case MarketSource.C5Game:
return 'c5';
default:
// csfloat can be queried via buff name
return null;
}
};
Expand Down
22 changes: 7 additions & 15 deletions src/lib/inline/SpBuffContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type BuffItem = {
priceOrder: number;
priceAvg30: number;
liquidity: number;
link: string;
};

const Container: React.FC<{ child: HTMLDivElement }> = ({ child }) => {
Expand All @@ -33,6 +34,7 @@ const SPBuffContainer: React.FC = () => {
priceOrder: parseFloat(jsonData.priceOrder || 0),
priceAvg30: parseFloat(jsonData.priceAvg30 || 0),
liquidity: parseFloat(jsonData.liquidity || 0),
link: String(jsonData.link),
};

const marketIcon = AvailableMarketSources.find((s) => s.source === data.source)?.logo ?? ICON_BUFF;
Expand Down Expand Up @@ -78,19 +80,7 @@ const SPBuffContainer: React.FC = () => {
};

const openBuffPage = () => {
const getMarketURL = () => {
switch (data.source) {
case MarketSource.Buff:
return data.buff_id > 0 ? `https://buff.163.com/goods/${data.buff_id}` : `https://buff.163.com/market/csgo#tab=selling&page_num=1&search=${encodeURIComponent(data.buff_name)}`;
case MarketSource.Steam:
return `https://steamcommunity.com/market/listings/730/${encodeURIComponent(data.buff_name)}`;
case MarketSource.YouPin:
return `https://youpin898.com/search?keyword=${encodeURIComponent(data.buff_name)}`;
case MarketSource.C5Game:
return `https://www.c5game.com/csgo?marketKeyword=${encodeURIComponent(data.buff_name)}`;
}
};
window.open(getMarketURL(), '_blank');
window.open(data.link, '_blank');
};

return (
Expand Down Expand Up @@ -166,8 +156,10 @@ const SPBuffContainer: React.FC = () => {
</PopoverClose>
</PopoverContent>
</Popover>
<Button variant="ghost" size="icon" className="hover:bg-neutral-500/70" onClick={openBuffPage}>
<img src={ICON_ARROWUP} className="h-6 w-6" />
<Button variant="ghost" size="icon" className="hover:bg-neutral-500/70" asChild>
<a href={data.link} target="_blank" rel="noreferrer">
<img src={ICON_ARROWUP} className="h-6 w-6" />
</a>
</Button>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions src/lib/util/helperfunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ export function getMarketURL({ source, buff_name, market_id = 0, phase }: { sour
return `https://www.c5game.com/en/csgo?marketKeyword=${encodeURIComponent(buff_name)}`;
}
}
case MarketSource.CSFloat:
return `https://csfloat.com/search?sort_by=lowest_price&type=buy_now&market_hash_name=${encodeURIComponent(buff_name)}`;
}
return '';
}
Expand Down

0 comments on commit bfe33ad

Please sign in to comment.