Skip to content

Commit

Permalink
Improve CSFloat detection
Browse files Browse the repository at this point in the history
  • Loading branch information
GODrums committed Mar 11, 2025
1 parent 7183131 commit a755a77
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
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.1.8",
"version": "3.1.9",
"description": "Enhance your website experience on 9+ CS2 skin markets!",
"author": "Rums",
"license": "CC BY NC SA 4.0",
Expand Down
6 changes: 5 additions & 1 deletion src/background/messages/refreshPrices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ const handler: PlasmoMessaging.MessageHandler<PriceBody, PriceResponse> = async
if (responseJson?.data) {
await chrome.storage.local.set({
[`${pricesURL}`]: JSON.stringify(responseJson.data),
[`${source}-update`]: Date.now(), // responseJson.time,
[`${source}-update`]: Date.now(),
});
}
} else if (response.status === 403) {
await chrome.storage.local.set({
[`${source}-update`]: Date.now(), // avoid refetches until auth is resolved
});
}
res.send({
status: response.status,
Expand Down
29 changes: 24 additions & 5 deletions src/contents/csfloat_script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ async function init() {
// required as mutation does not detect initial DOM
async function firstLaunch() {
let items = document.querySelectorAll('item-card');
while (items.length === 0 && (location.pathname === '/search' || location.pathname.startsWith('/item/'))) {
let tries = 20;
while (items.length === 0 && tries-- > 0) {
await new Promise((r) => setTimeout(r, 100));
items = document.querySelectorAll('item-card');
}
// console.log('[BetterFloat] Found', items.length, 'items');

for (let i = 0; i < items.length; i++) {
const popoutVersion = items[i].getAttribute('width')?.includes('100%')
Expand All @@ -134,14 +136,28 @@ async function firstLaunch() {
await adjustItem(items[i], popoutVersion);
}

if (items.length < 40) {
const newItems = document.querySelectorAll('item-card');
for (let i = 0; i < newItems.length; i++) {
const popoutVersion = newItems[i].getAttribute('width')?.includes('100%')
? POPOUT_ITEM.PAGE
: newItems[i].className.includes('flex-item') || location.pathname === '/'
? POPOUT_ITEM.NONE
: POPOUT_ITEM.SIMILAR;
await adjustItem(newItems[i], popoutVersion);
}
}

if (location.pathname.startsWith('/item/')) {
// enhance item page
let popoutItem = document.querySelector('.grid-item > item-card');
while (!popoutItem) {
await new Promise((r) => setTimeout(r, 100));
popoutItem = document.querySelector('.grid-item > item-card');
if (!popoutItem?.querySelector('.betterfloat-buff-a')) {
while (!popoutItem) {
await new Promise((r) => setTimeout(r, 100));
popoutItem = document.querySelector('.grid-item > item-card');
}
await adjustItem(popoutItem, POPOUT_ITEM.PAGE);
}
await adjustItem(popoutItem, POPOUT_ITEM.PAGE);

// enhance similar items
let similarItems = document.querySelectorAll('app-similar-items item-card');
Expand Down Expand Up @@ -562,6 +578,9 @@ function addScreenshotListener(container: Element, item: CSFloat.Item) {
}

async function adjustItem(container: Element, popout = POPOUT_ITEM.NONE) {
if (container.querySelector('.betterfloat-buff-a')) {
return;
}
if (popout > 0) {
// wait for popup UI to load
await new Promise((r) => setTimeout(r, 100));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/util/uigeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function generatePriceLine({
}
</div>
${
(source === MarketSource.Buff || source === MarketSource.Steam) && isWarning
showBothPrices && isWarning
? html`
<img
src="${ICON_EXCLAMATION}"
Expand Down

0 comments on commit a755a77

Please sign in to comment.