feat: 新增美团脚本

This commit is contained in:
duanshuwen
2026-03-11 21:56:41 +08:00
parent 07d3e10056
commit f084e47c58
6 changed files with 58 additions and 8 deletions

View File

@@ -42,13 +42,15 @@ export function runTaskOperationService() {
})
const results: any[] = []
for (const item of scriptPaths) {
for (let i = 0; i < scriptPaths.length; i++) {
const item = scriptPaths[i]
log.info(`Launching script for channel ${item.channel}: ${item.scriptPath}`)
const result = await executeScriptServiceInstance.executeScript(item.scriptPath, {
roomType: roomType[item.channel],
startTime: options.startTime,
endTime: options.endTime,
operation: options.operation,
tabIndex: i,
})
results.push({
channel: item.channel,

View File

@@ -91,10 +91,9 @@ const toggleRoomByDateIndex = async (page, container, { roomType, dateIndex, ope
};
(async () => {
let browser;
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
try {
browser = await chromium.connectOverCDP(`http://127.0.0.1:9222`);
const context = browser.contexts()[0];
await context.addInitScript(() => {
@@ -102,8 +101,8 @@ const toggleRoomByDateIndex = async (page, container, { roomType, dateIndex, ope
});
const pages = await context.pages();
const page = pages.length ? pages[0] : await context.newPage();
const tabIndex = Number(process.env.TAB_INDEX);
const page = pages.length ? pages[tabIndex] : await context.newPage();
await page.goto('https://hotel.fliggy.com/ebooking/hotelBaseInfoUv.htm#/ebk/homeV1');

3
src/main/scripts/mt.md Normal file

File diff suppressed because one or more lines are too long

BIN
src/main/scripts/mt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

View File

@@ -1,4 +1,48 @@
import { chromium } from 'playwright';
import log from 'electron-log';
log.info('mt_trace.mjs placeholder: not implemented');
process.exit(0);
const getOrCreateTab = async (context, targetIndex) => {
const idx =
Number.isFinite(targetIndex) && targetIndex >= 0 ? Math.floor(targetIndex) : 1;
let pages = await context.pages();
while (pages.length <= idx) {
await context.newPage();
pages = await context.pages();
}
const page = pages[idx];
await page.bringToFront();
return page;
};
(async () => {
const browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
try {
const context = browser.contexts()[0];
if (!context) {
throw new Error('No browser context available');
}
await context.addInitScript(() => {
Object.defineProperty(navigator, 'webdriver', { get: () => undefined });
});
const tabIndex = Number(process.env.TAB_INDEX);
const page = await getOrCreateTab(context, tabIndex);
await page.goto('https://me.meituan.com/ebooking/merchant/product#/index');
} catch (error) {
log.error(error);
process.exitCode = 1;
} finally {
if (browser) {
try {
if (typeof browser.disconnect === 'function') {
await browser.disconnect();
} else {
await browser.close();
}
} catch {}
}
}
})();

View File

@@ -22,6 +22,7 @@ export class executeScriptService extends EventEmitter {
const startTime = options?.startTime ?? '';
const endTime = options?.endTime ?? '';
const operation = options?.operation ?? '';
const tabIndex = options?.tabIndex ?? '';
const child = spawn('node', [scriptPath], {
env: {
@@ -29,7 +30,8 @@ export class executeScriptService extends EventEmitter {
ROOM_TYPE: String(roomType),
START_DATE: String(startTime),
END_DATE: String(endTime),
OPERATION: String(operation)
OPERATION: String(operation),
TAB_INDEX: String(tabIndex),
},
});