29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
// 桥接客户端:node cdb.mjs <exprFile> [saveAs] [matchRegex] [createUrl] [waitMs]
|
|
// 通过常驻桥发指令,不会触发新的 Chrome 授权弹窗。
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const [, , exprFile, saveAs, match, createUrl, waitMs] = process.argv;
|
|
if (!exprFile) { console.error('usage: node cdb.mjs <exprFile> [saveAs] [matchRegex] [createUrl] [waitMs]'); process.exit(1); }
|
|
|
|
const portFile = path.resolve('.cdp/bridge-port.txt');
|
|
if (!fs.existsSync(portFile)) { console.error('桥接未启动:缺少 .cdp/bridge-port.txt'); process.exit(1); }
|
|
const port = fs.readFileSync(portFile, 'utf8').trim();
|
|
const expr = fs.readFileSync(path.resolve(exprFile), 'utf8');
|
|
|
|
const body = {
|
|
expr,
|
|
saveAs: saveAs || null,
|
|
match: match || 'seller\\.goofish\\.com',
|
|
createUrl: createUrl || undefined,
|
|
waitMs: waitMs ? Number(waitMs) : 6000,
|
|
};
|
|
|
|
const res = await fetch(`http://127.0.0.1:${port}/eval`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json; charset=utf-8' },
|
|
body: JSON.stringify(body),
|
|
});
|
|
const out = await res.json();
|
|
console.log(JSON.stringify(out, null, 2));
|