added easyOCR
This commit is contained in:
parent
37d6678577
commit
9f208b0606
27 changed files with 1780 additions and 112 deletions
|
|
@ -3,7 +3,7 @@ import { chromium, type Browser, type BrowserContext, type Page, type WebSocket
|
|||
import { SELECTORS } from './selectors.js';
|
||||
import { logger } from '../util/logger.js';
|
||||
import { sleep } from '../util/sleep.js';
|
||||
import type { Config } from '../types.js';
|
||||
import type { Config, TradeItem } from '../types.js';
|
||||
|
||||
// Stealth JS injected into every page to avoid Playwright detection
|
||||
const STEALTH_SCRIPT = `
|
||||
|
|
@ -226,6 +226,40 @@ export class TradeMonitor extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
async openScrapPage(tradeUrl: string): Promise<{ page: Page; items: TradeItem[] }> {
|
||||
if (!this.context) throw new Error('Browser not started');
|
||||
|
||||
const page = await this.context.newPage();
|
||||
const items: TradeItem[] = [];
|
||||
|
||||
page.on('response', async (response) => {
|
||||
if (response.url().includes('/api/trade2/fetch/')) {
|
||||
try {
|
||||
const json = await response.json();
|
||||
if (json.result && Array.isArray(json.result)) {
|
||||
for (const r of json.result) {
|
||||
items.push({
|
||||
id: r.id,
|
||||
w: r.item?.w ?? 1,
|
||||
h: r.item?.h ?? 1,
|
||||
stashX: r.listing?.stash?.x ?? 0,
|
||||
stashY: r.listing?.stash?.y ?? 0,
|
||||
account: r.listing?.account?.name ?? '',
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Response may not be JSON
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await page.goto(tradeUrl, { waitUntil: 'networkidle' });
|
||||
await sleep(2000); // ensure API response received
|
||||
logger.info({ url: tradeUrl, itemCount: items.length }, 'Scrap page opened');
|
||||
return { page, items };
|
||||
}
|
||||
|
||||
extractSearchId(url: string): string {
|
||||
const cleaned = url.replace(/\/live\/?$/, '');
|
||||
const parts = cleaned.split('/');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue