dsh-qianchuan-toolkit 1.0.21 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +109 -0
- package/README.md +6 -4
- package/assets/live-control/scripts/account-lib.mjs +35 -11
- package/assets/live-control/scripts/cdp-lib.mjs +11 -4
- package/assets/live-control/scripts/control.mjs +14 -3
- package/assets/live-control/scripts/expr/cancel-modal-sq.js +11 -0
- package/assets/live-control/scripts/expr/close-dialog-sq.js +12 -0
- package/assets/live-control/scripts/expr/dialog-open-sq.js +7 -0
- package/assets/live-control/scripts/expr/dismiss-overlays-sq.js +37 -0
- package/assets/live-control/scripts/expr/fill-sq.js +68 -0
- package/assets/live-control/scripts/expr/log-rows.js +10 -0
- package/assets/live-control/scripts/expr/log-tab-click.js +9 -0
- package/assets/live-control/scripts/expr/manifest.json +144 -0
- package/assets/live-control/scripts/expr/open-plus-sq.js +40 -0
- package/assets/live-control/scripts/expr/page-state-sq.js +15 -0
- package/assets/live-control/scripts/expr/pause-info-sq.js +57 -0
- package/assets/live-control/scripts/expr/pick-sq.js +51 -0
- package/assets/live-control/scripts/expr/plus-rect-sq.js +24 -0
- package/assets/live-control/scripts/expr/result-sq.js +21 -0
- package/assets/live-control/scripts/expr/row-mode-sq.js +23 -0
- package/assets/live-control/scripts/expr/row-state-sq.js +72 -0
- package/assets/live-control/scripts/expr/submit-dom-sq.js +16 -0
- package/assets/live-control/scripts/expr/submit-rect-sq.js +15 -0
- package/assets/live-control/scripts/expr-util.mjs +18 -1
- package/assets/live-control/scripts/hourly.mjs +70 -18
- package/assets/material-align/SKILL.md +88 -0
- package/assets/material-align/references/01-/345/214/271/351/205/215/350/247/204/345/210/231/344/270/216/345/255/227/346/256/265/345/217/243/345/276/204.md +60 -0
- package/assets/material-align/scripts/align.mjs +284 -0
- package/assets/material-align/scripts/db.mjs +154 -0
- package/assets/material-align/scripts/xlsx.mjs +304 -0
- package/assets/plan-copy/SKILL.md +24 -4
- package/assets/plan-copy/references/01-/345/256/214/346/225/264/346/223/215/344/275/234/346/211/213/345/206/214.md +3 -3
- package/assets/plan-copy/references/04-/346/265/217/350/247/210/345/231/250/344/274/232/350/257/235.md +3 -3
- package/assets/plan-copy/references/05-/345/274/271/347/252/227/346/270/205/345/215/225.md +58 -0
- package/assets/plan-copy/scripts/capture.mjs +67 -1
- package/assets/plan-copy/scripts/cdp.mjs +3 -1
- package/assets/plan-copy/scripts/copy.mjs +130 -20
- package/assets/plan-copy/scripts/newmat.mjs +399 -0
- package/assets/plan-copy/scripts/pick-all.mjs +110 -4
- package/assets/plan-copy/scripts/readmat.mjs +2 -0
- package/assets/plan-copy/scripts/start-qc-copy.cmd +49 -0
- package/lib/index.js +6 -0
- package/package.json +5 -3
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
// 用法: node capture.mjs <aavid> <planId> <outJson> [newDateSuffix]
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import { connect, sleep, listPages } from '../../live-control/scripts/cdp-lib.mjs';
|
|
6
|
+
// 复制技能固定连 9223 的独立浏览器实例(与 9222 的巡航实例物理隔离,互不抢标签)。
|
|
7
|
+
process.env.QC_CDP_PORT = process.env.QC_CDP_PORT || '9223';
|
|
6
8
|
|
|
7
|
-
const
|
|
9
|
+
const __d = new Date();
|
|
10
|
+
const __def = String(__d.getMonth() + 1).padStart(2, '0') + String(__d.getDate()).padStart(2, '0');
|
|
11
|
+
const aavid = process.argv[2], planId = process.argv[3], outFile = process.argv[4], suffix = process.argv[5] || __def;
|
|
8
12
|
if (!aavid || !planId || !outFile) { console.log('usage: node capture.mjs <aavid> <planId> <outJson> [suffix]'); process.exit(2); }
|
|
9
13
|
const listUrl = 'https://qianchuan.jinritemai.com/overall-prom?aavid=' + aavid + '&campaignType=1&uniTab=ad&uniVideoTab=1&overallPromViewTab=plan';
|
|
10
14
|
const t0 = Date.now();
|
|
@@ -97,6 +101,46 @@ async function matFn() {
|
|
|
97
101
|
return JSON.stringify({ mat: m, snip: i >= 0 ? t.slice(Math.max(0, i - 60), i + 60) : t.slice(0, 160) });
|
|
98
102
|
}
|
|
99
103
|
|
|
104
|
+
async function matListFn() {
|
|
105
|
+
const T = (s) => (s || '').replace(/[\s\u00a0]+/g, ' ').trim();
|
|
106
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
107
|
+
const ct = (w) => { const els = [...document.querySelectorAll('div,span,li,a,button')].filter((x) => T(x.innerText) === w && x.getBoundingClientRect().width > 0 && x.getBoundingClientRect().y < 210); if (!els.length) return 'miss'; els[els.length - 1].click(); return 'ok' };
|
|
108
|
+
ct('素材'); await sleep(3500);
|
|
109
|
+
const sampleH = [];
|
|
110
|
+
const parse = () => {
|
|
111
|
+
const byId = new Map();
|
|
112
|
+
const nodes = [...document.querySelectorAll('div,tr,li')].filter((e) => { const t = e.innerText || ''; return /素材ID[::]\s*[0-9]{8,}/.test(t) && /\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}/.test(t) });
|
|
113
|
+
for (const r of nodes) {
|
|
114
|
+
const t = (r.innerText || '').replace(/[\s\u00a0]+/g, ' ');
|
|
115
|
+
const m = t.match(/素材ID[::]\s*([0-9]{8,})/);
|
|
116
|
+
if (!m) continue;
|
|
117
|
+
if (sampleH.length < 2) sampleH.push(String(r.outerHTML).slice(0, 900));
|
|
118
|
+
const img = r.querySelector('img');
|
|
119
|
+
const src = img ? String(img.src || '') : '';
|
|
120
|
+
const km = src.match(/tos-cn-[^\/]+\/([^~?]+)/);
|
|
121
|
+
const key = km ? km[1] : '';
|
|
122
|
+
const am = t.match(/([^\s]{1,30})\s+ID[::]\s*([A-Za-z0-9_]{5,})\s*-\s*(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/);
|
|
123
|
+
const rec = { id: m[1], row: t.slice(0, 400), img: key, aweme: am ? am[1] : '', awemeId: am ? am[2] : '', date: am ? am[3] : '' };
|
|
124
|
+
const prev = byId.get(m[1]);
|
|
125
|
+
if (!prev || t.length < prev.row.length) byId.set(m[1], rec);
|
|
126
|
+
}
|
|
127
|
+
return [...byId.values()];
|
|
128
|
+
};
|
|
129
|
+
const pagerItems = () => [...document.querySelectorAll('li.main-vmok-plugin-page-turner__item')].filter((e) => /^\d+$/.test(T(e.innerText)) && e.getBoundingClientRect().x > 1000);
|
|
130
|
+
let all = parse();
|
|
131
|
+
const pages = pagerItems().map((e) => T(e.innerText));
|
|
132
|
+
for (const p of pages) {
|
|
133
|
+
if (p === '1') continue;
|
|
134
|
+
const li = pagerItems().find((e) => T(e.innerText) === p);
|
|
135
|
+
if (!li) continue;
|
|
136
|
+
li.click(); await sleep(2800);
|
|
137
|
+
all = all.concat(parse());
|
|
138
|
+
}
|
|
139
|
+
const seen = new Set(); const list = [];
|
|
140
|
+
for (const a of all) { if (!seen.has(a.id)) { seen.add(a.id); list.push(a) } }
|
|
141
|
+
return JSON.stringify({ pages, count: list.length, list, sampleH });
|
|
142
|
+
}
|
|
143
|
+
|
|
100
144
|
async function pageFor() {
|
|
101
145
|
try {
|
|
102
146
|
const pages = await listPages();
|
|
@@ -112,6 +156,18 @@ const page = await pageFor();
|
|
|
112
156
|
await page.send('Page.navigate', { url: listUrl }, 20000);
|
|
113
157
|
mark('nav-done');
|
|
114
158
|
await sleep(3000);
|
|
159
|
+
if (process.argv.includes('--deleted')) {
|
|
160
|
+
await page.eval('(() => { const T = (s) => (s || "").replace(/[\s]+/g, " ").trim(); const a = [...document.querySelectorAll("*")].filter((x) => x.children.length === 0 && T(x.innerText) === "计划视图").pop(); if (a) a.click(); const b = [...document.querySelectorAll("*")].filter((x) => x.children.length === 0 && T(x.innerText) === "商品自选").pop(); if (b) b.click(); return 1 })()', undefined, 20000);
|
|
161
|
+
await sleep(5000);
|
|
162
|
+
const box = JSON.parse(await page.eval('(() => { const T = (s) => (s || "").replace(/[\s]+/g, " ").trim(); const leaf = [...document.querySelectorAll("*")].filter((x) => T(x.innerText) === "请筛选计划状态").pop(); if (!leaf) return "null"; let n = leaf; for (let i = 0; i < 5 && n; i++) { const r = n.getBoundingClientRect(); if (r.width > 120 && r.height > 20) return JSON.stringify({ x: Math.round(r.x + r.width / 2), y: Math.round(r.y + r.height / 2) }); n = n.parentElement } const r2 = leaf.getBoundingClientRect(); return JSON.stringify({ x: Math.round(r2.x + r2.width / 2), y: Math.round(r2.y + r2.height / 2) }) })()', undefined, 20000));
|
|
163
|
+
const clk = async (x, y) => { await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x, y }); await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x, y, button: 'left', clickCount: 1 }); await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x, y, button: 'left', clickCount: 1 }) };
|
|
164
|
+
const key = async (k, vk) => { await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key: k, code: k, windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk }); await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code: k, windowsVirtualKeyCode: vk, nativeVirtualKeyCode: vk }) };
|
|
165
|
+
if (!box) { mark('status-miss'); throw new Error('找不到计划状态筛选框') }
|
|
166
|
+
await clk(box.x, box.y); await sleep(1500);
|
|
167
|
+
for (let i = 0; i < 6; i++) { await key('ArrowDown', 40); await sleep(220) }
|
|
168
|
+
await key('Enter', 13); await sleep(3500);
|
|
169
|
+
mark('status-deleted')
|
|
170
|
+
}
|
|
115
171
|
const run = (fn, arg, timeout) => page.eval('window.__qcArg=' + JSON.stringify(arg) + ';(' + fn.toString() + ')()', timeout);
|
|
116
172
|
|
|
117
173
|
let prep = null;
|
|
@@ -127,6 +183,13 @@ const aw = JSON.parse(await run(awemesFn, planId, 120000));
|
|
|
127
183
|
mark('awemes', 'count=' + aw.count + ' pages=' + JSON.stringify(aw.pages) + ' products=' + JSON.stringify(aw.products).slice(0, 120));
|
|
128
184
|
const mat = JSON.parse(await run(matFn, 0, 60000));
|
|
129
185
|
mark('mat', JSON.stringify(mat));
|
|
186
|
+
let matList = { pages: [], count: 0, list: [] };
|
|
187
|
+
try {
|
|
188
|
+
matList = JSON.parse(await run(matListFn, 0, 120000));
|
|
189
|
+
mark('matlist', 'count=' + matList.count + ' pages=' + JSON.stringify(matList.pages));
|
|
190
|
+
} catch (e) {
|
|
191
|
+
mark('matlist-err', String(e.message).slice(0, 90));
|
|
192
|
+
}
|
|
130
193
|
|
|
131
194
|
const nums = (row.match(/综合营销ROI目标\s*([0-9.]+)/) || [])[1] || '';
|
|
132
195
|
const budget = (row.match(/每日预算\s*([0-9.]+)/) || [])[1] || '';
|
|
@@ -137,6 +200,7 @@ const planName = prep.name || '';
|
|
|
137
200
|
let newName = planName;
|
|
138
201
|
if (/--\d{4}$/.test(planName)) newName = planName.replace(/--\d{4}$/, '--' + suffix);
|
|
139
202
|
else if (/--\d{4}/.test(planName)) newName = planName.replace(/--\d{4}(?!.*--\d{4})/, '--' + suffix);
|
|
203
|
+
else if (/-\d{4}$/.test(planName)) newName = planName.replace(/-\d{4}$/, '--' + suffix);
|
|
140
204
|
else newName = planName + '--' + suffix;
|
|
141
205
|
|
|
142
206
|
const awemeNames = {};
|
|
@@ -149,6 +213,8 @@ const params = {
|
|
|
149
213
|
productName: prodIds.length ? aw.products[prodIds[0]] : '',
|
|
150
214
|
awemeIds, awemeNames,
|
|
151
215
|
roi: nums, budget,
|
|
216
|
+
materialsList: matList.list,
|
|
217
|
+
materialsListCount: matList.count,
|
|
152
218
|
origin: { planId, planName, state, awemes: aw.count, chipAwemes: chip, materials: mat.mat },
|
|
153
219
|
note: 'capture.mjs ' + new Date().toISOString()
|
|
154
220
|
};
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
// 与 assets/live-control/scripts/cdp-lib.mjs 的分工:cdp-lib 是巡航库(被 hourly/control 等 import),
|
|
4
4
|
// 本文件是手动跑批的命令行工具。两者不通用、不要互相 import;删除本文件会破坏文档化工作流。
|
|
5
5
|
import fs from 'node:fs'
|
|
6
|
-
|
|
6
|
+
// 复制技能固定连 9223 的独立浏览器实例(与 9222 的巡航实例物理隔离,互不抢标签)。
|
|
7
|
+
process.env.QC_CDP_PORT = process.env.QC_CDP_PORT || '9223'
|
|
8
|
+
const PORT = Number(process.env.QC_CDP_PORT || process.env.CDP_PORT || 9222)
|
|
7
9
|
const BASE = 'http://127.0.0.1:' + PORT
|
|
8
10
|
|
|
9
11
|
async function j(path) {
|
|
@@ -7,6 +7,8 @@ import os from 'node:os';
|
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import { pickAllOnTarget } from './pick-all.mjs';
|
|
9
9
|
import { connect, sleep, listPages, browserSend } from '../../live-control/scripts/cdp-lib.mjs';
|
|
10
|
+
// 复制技能固定连 9223 的独立浏览器实例(与 9222 的巡航实例物理隔离,互不抢标签)。
|
|
11
|
+
process.env.QC_CDP_PORT = process.env.QC_CDP_PORT || '9223';
|
|
10
12
|
|
|
11
13
|
// 确认单/截图落盘根目录:默认当前工作目录(可移植),需要固定位置时用 QC_WORKDIR 指定。
|
|
12
14
|
// confirm 与 delete 必须在同一个 QC_WORKDIR 下运行,否则找不到确认单。
|
|
@@ -203,8 +205,12 @@ async function cmdDelete() {
|
|
|
203
205
|
await openList(page, aavid);
|
|
204
206
|
const hit = (await searchPlan(page, planId)) !== 'miss';
|
|
205
207
|
if (!hit) throw new Error('未唯一命中,拒绝删除');
|
|
208
|
+
// 用户 2026-11-26:搜索到删除之间停 1.5s,等页面完全加载,规避加载中删错
|
|
209
|
+
await sleep(1500);
|
|
210
|
+
const guard = await page.eval('(() => { const c=(s)=>(s||"").replace(/\s+/g," ").trim(); const trs=[...document.querySelectorAll("tbody tr")].filter(r=>{const t=c(r.innerText); return t.includes("ID:") && t.includes("每日预算") && !t.includes("素材ID")}); if(trs.length!==1) return "rows="+trs.length; return c(trs[0].innerText).includes(' + JSON.stringify(planId) + ') ? "ok" : "other-row:"+c(trs[0].innerText).slice(0,60) })()');
|
|
211
|
+
if (guard !== 'ok') throw new Error('删除前校验失败:' + guard);
|
|
206
212
|
mark('unique-hit');
|
|
207
|
-
const clicked = await page.eval('(() => { const c=(s)=>(s||"").replace(/\s+/g," ").trim(); const tr=[...document.querySelectorAll("tbody tr")].
|
|
213
|
+
const clicked = await page.eval('(() => { const c=(s)=>(s||"").replace(/\s+/g," ").trim(); const tr=[...document.querySelectorAll("tbody tr")].filter(r=>{const t=c(r.innerText); return t.includes(' + JSON.stringify(planId) + ') && t.includes("每日预算") && !t.includes("素材ID")})[0]; if(!tr) return "norow"; const b=[...tr.querySelectorAll("*")].filter(e=>e.children.length===0 && c(e.innerText)==="删除").pop(); if(!b) return "nobtn"; b.click(); return "ok" })()');
|
|
208
214
|
if (clicked !== 'ok') throw new Error('删除按钮: ' + clicked);
|
|
209
215
|
const dlg = await wait(page, '[...document.querySelectorAll("*")].some(e=>(e.innerText||"").trim()==="确定要删除计划吗?")', 6000);
|
|
210
216
|
if (!dlg) throw new Error('删除弹窗未出现');
|
|
@@ -221,10 +227,34 @@ async function cmdConfirm() {
|
|
|
221
227
|
if (!planId) throw new Error('用法: copy.mjs confirm <aavid> <planId>');
|
|
222
228
|
const page = await connectFor(aavid);
|
|
223
229
|
await openList(page, aavid);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
230
|
+
// 用户 2026-11-26:进页面先关掉残留的抽屉/弹窗,避免影响操作
|
|
231
|
+
await page.eval('(() => { document.dispatchEvent(new KeyboardEvent("keydown",{key:"Escape",keyCode:27,bubbles:true})); [...document.querySelectorAll(".aurora-qc-modal-close,.aurora-qc-drawer-close,.semi-icon-close,.semi-modal-close")].forEach(e=>{ try{ e.click() }catch(_){} }); return 1 })()');
|
|
232
|
+
await sleep(600);
|
|
233
|
+
// 若当前列表已经是「唯一命中该 ID」状态(capture 刚搜过),直接截图,不再重复搜索
|
|
234
|
+
const already = await page.eval('(() => { const c=(s)=>(s||"").replace(/\s+/g," ").trim(); const inp=[...document.querySelectorAll("input")].find(x=>/回车搜索|计划名称|计划ID|计划 ID/.test(x.placeholder||"")); const trs=[...document.querySelectorAll("tbody tr")].filter(r=>c(r.innerText).includes("ID:")); if(!inp || c(inp.value)!==(' + JSON.stringify(planId) + ')) return "no"; return (trs.length===1 && c(trs[0].innerText).includes(' + JSON.stringify(planId) + ')) ? "ok" : "no" })()');
|
|
235
|
+
if (already === 'ok') { mark('confirm-reuse', 'skip-extra-search'); }
|
|
236
|
+
else {
|
|
237
|
+
const hit = (await searchPlan(page, planId)) !== 'miss';
|
|
238
|
+
if (!hit) throw new Error('拒绝出确认图:搜索结果里没有唯一该 ID 的行');
|
|
239
|
+
}
|
|
240
|
+
const row = await page.eval('(() => { const c=(s)=>(s||"").replace(/\s+/g," ").trim(); const tr=[...document.querySelectorAll("tbody tr")].filter(r=>{const t=c(r.innerText); return t.includes(' + JSON.stringify(planId) + ') && t.includes("每日预算") && !t.includes("素材ID")})[0]; return tr ? c(tr.innerText) : "norow" })()');
|
|
227
241
|
if (row === 'norow') throw new Error('拒绝出确认图:列表里没有该 ID 的行');
|
|
242
|
+
// 用户 2026-11-26:截图前必须先按回车刷新计数,等「共N条计划」变成 1,避免残留旧计数(曾出现共45条)
|
|
243
|
+
const pressEnter = '(() => { const i=[...document.querySelectorAll("input")].find(x=>/回车搜索|计划名称|计划ID/.test(x.placeholder||"")); if(!i) return "noinput"; i.focus(); i.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter",code:"Enter",keyCode:13,which:13,bubbles:true})); i.dispatchEvent(new KeyboardEvent("keyup",{key:"Enter",code:"Enter",keyCode:13,which:13,bubbles:true})); return "enter" })()';
|
|
244
|
+
const readCount = '(() => { const t=document.body.innerText||""; const m=t.match(/共\s*(\d+)\s*条(?:计划|记录)/); const r=[...document.querySelectorAll("tbody tr")].filter(x=>(x.innerText||"").includes("ID:")).length; return (m?m[1]:"-1")+"|"+r })()';
|
|
245
|
+
let cnt = "-1", rows = "0";
|
|
246
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
247
|
+
await page.eval(pressEnter);
|
|
248
|
+
for (let k = 0; k < 25; k++) {
|
|
249
|
+
await sleep(600);
|
|
250
|
+
const cv = String(await page.eval(readCount)).split("|");
|
|
251
|
+
cnt = cv[0]; rows = cv[1] || "0";
|
|
252
|
+
if (cnt === "1" || rows === "1") break;
|
|
253
|
+
}
|
|
254
|
+
if (cnt === "1" || rows === "1") break;
|
|
255
|
+
}
|
|
256
|
+
mark("confirm-count", "共" + cnt + "条计划 行=" + rows);
|
|
257
|
+
if (!(cnt === "1" || rows === "1")) console.log("WARN 截图前计数不是1:共" + cnt + "条计划 行=" + rows);
|
|
228
258
|
const outDir = path.join(W, 'qc');
|
|
229
259
|
fs.mkdirSync(outDir, { recursive: true });
|
|
230
260
|
const shot = path.join(outDir, 'confirm-' + planId + '.png');
|
|
@@ -321,6 +351,7 @@ async function cmdCreate() {
|
|
|
321
351
|
|
|
322
352
|
await focusAndType(page, ROI_INPUT, p.roi);
|
|
323
353
|
await focusAndType(page, BUDGET_INPUT, p.budget);
|
|
354
|
+
if (process.env.QC_METRIC === '1h') mark('metric24', 'skip(1h)'); else await ensureMetric24(page);
|
|
324
355
|
await focusAndType(page, NAME_INPUT, p.planName);
|
|
325
356
|
const vals = await page.eval('JSON.stringify({ nums: [...document.querySelectorAll(".aurora-qc-input-number-input")].map(x => x.value), name: (' + NAME_INPUT + ' || {}).value })');
|
|
326
357
|
mark('form', vals);
|
|
@@ -333,11 +364,74 @@ async function cmdCreate() {
|
|
|
333
364
|
// → 逐抖音号全选 → 一次确定。禁止走 create-ad?type=e 编辑页加素材。
|
|
334
365
|
const BUBBLE_TEXTS = ['我知道了', '知道了', '不再提示', '跳过'];
|
|
335
366
|
|
|
367
|
+
async function clickAt(page, x, y) {
|
|
368
|
+
try {
|
|
369
|
+
await page.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: x, y: y }, 8000);
|
|
370
|
+
await page.send('Input.dispatchMouseEvent', { type: 'mousePressed', x: x, y: y, button: 'left', clickCount: 1 }, 8000);
|
|
371
|
+
await page.send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: x, y: y, button: 'left', clickCount: 1 }, 8000);
|
|
372
|
+
} catch (e) { }
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// ---------- 净成交口径(平台 2026-12 新增,用户 2026-12-02 要求)----------
|
|
376
|
+
// 创编页「综合营销ROI目标」右侧有两个单选项:1小时净成交金额 / 24小时净成交金额。
|
|
377
|
+
// 新建计划默认选 1 小时;用户要求新建时必须选 24 小时。DOM 实测(2026-12-02):
|
|
378
|
+
// label.aurora-qc-radio-button-wrapper → 选中态 class 含 -checked;未选中的 label 没有该 class。
|
|
379
|
+
// 想保留 1 小时口径时用 QC_METRIC=1h。
|
|
380
|
+
const METRIC24 = '24小时净成交金额';
|
|
381
|
+
function metricProbe(t) {
|
|
382
|
+
return '(() => { const T=(s)=>(s||"").replace(/[\s\u00a0]+/g," ").trim();'
|
|
383
|
+
+ ' const labs=[...document.querySelectorAll("label.aurora-qc-radio-button-wrapper")].filter((x)=>x.getBoundingClientRect().width>0);'
|
|
384
|
+
+ ' const hit=labs.find((x)=>T(x.innerText).indexOf(' + JSON.stringify(t) + ')>=0);'
|
|
385
|
+
+ ' if(!hit) return "none"; const r=hit.getBoundingClientRect();'
|
|
386
|
+
+ ' return JSON.stringify({checked:/-checked/.test(String(hit.className||"")), x:Math.round(r.x+r.width/2), y:Math.round(r.y+r.height/2)}) })()'
|
|
387
|
+
}
|
|
388
|
+
async function ensureMetric24(page) {
|
|
389
|
+
// P3(2026-12-02 实测):创编页会冒出火萤弹窗「24小时净成交优化目标已上线…」,它压住营销目标区、
|
|
390
|
+
// 把口径的鼠标点击吞掉(点了不生效)→ 每次切口径前先把已登记气泡关掉,再点。
|
|
391
|
+
const bd = await dismissBubbles(page, 0).catch(() => 'err');
|
|
392
|
+
mark('metric24-bubble', String(bd));
|
|
393
|
+
await sleep(700);
|
|
394
|
+
let st = null;
|
|
395
|
+
for (let i = 0; i < 8; i++) {
|
|
396
|
+
const s = await page.eval(metricProbe(METRIC24), 20000).catch(() => 'none');
|
|
397
|
+
if (s === 'none') { await sleep(600); continue }
|
|
398
|
+
st = JSON.parse(s);
|
|
399
|
+
break
|
|
400
|
+
}
|
|
401
|
+
if (!st) { mark('metric24', 'none-option'); throw new Error('创编页没找到「' + METRIC24 + '」选项') }
|
|
402
|
+
if (st.checked) { mark('metric24', 'ok(already)'); return 'ok' }
|
|
403
|
+
await page.eval('(() => { const T=(s)=>(s||"").replace(/[\s\u00a0]+/g," ").trim(); const hit=[...document.querySelectorAll("label.aurora-qc-radio-button-wrapper")].find((x)=>T(x.innerText).indexOf(' + JSON.stringify(METRIC24) + ')>=0); if(hit) hit.scrollIntoView({block:"center"}); return 1 })()', 15000).catch(() => {});
|
|
404
|
+
await sleep(300);
|
|
405
|
+
// 点一下被吞(弹窗/重算)时重试,最多 3 次;每次点前重新取坐标
|
|
406
|
+
for (let att = 0; att < 3; att++) {
|
|
407
|
+
const s2 = await page.eval(metricProbe(METRIC24), 20000).catch(() => 'none');
|
|
408
|
+
if (s2 === 'none') { await sleep(700); continue }
|
|
409
|
+
const p2 = JSON.parse(s2);
|
|
410
|
+
if (p2.checked) { mark('metric24', 'ok(clicked)'); return 'ok' }
|
|
411
|
+
if (att > 0) { await dismissBubbles(page, 0).catch(() => {}); await sleep(600) }
|
|
412
|
+
await clickAt(page, p2.x, p2.y)
|
|
413
|
+
for (let i = 0; i < 8; i++) {
|
|
414
|
+
await sleep(350);
|
|
415
|
+
const s = await page.eval(metricProbe(METRIC24), 20000).catch(() => 'none');
|
|
416
|
+
if (s !== 'none' && JSON.parse(s).checked) { mark('metric24', 'ok(clicked)'); return 'ok' }
|
|
417
|
+
}
|
|
418
|
+
mark('metric24-retry', 'att=' + att);
|
|
419
|
+
}
|
|
420
|
+
mark('metric24', 'fail');
|
|
421
|
+
throw new Error('净成交口径没能切到「' + METRIC24 + '」')
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// 气泡(火萤引导等)的 innerText 常为空、文字只在 textContent,且可能挂在 shadowRoot 里 →
|
|
425
|
+
// 走 textContent 全量遍历 + CDP 真实鼠标点击(JS .click() 对火萤无效)
|
|
336
426
|
async function dismissBubbles(page, depth = 0) {
|
|
337
427
|
if (depth > 3) return 'deeper';
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
return
|
|
428
|
+
const find = '(() => { const texts = ' + JSON.stringify(BUBBLE_TEXTS) + '; const out = []; const walk = (root) => { for (const e of root.querySelectorAll("span,div,button,a")) { const t = String(e.textContent || "").replace(/[\\s\\u00a0]+/g, ""); if (texts.indexOf(t) < 0) continue; const r = e.getBoundingClientRect(); if (r.width > 0 && r.height > 0) out.push({ x: Math.round(r.x + r.width / 2), y: Math.round(r.y + r.height / 2), a: r.width * r.height }); if (e.shadowRoot) walk(e.shadowRoot) } }; walk(document); out.sort((a, b) => a.a - b.a); return out })()';
|
|
429
|
+
let arr = [];
|
|
430
|
+
try { arr = await page.eval(find, 8000) } catch (e) { return 'eval-fail' }
|
|
431
|
+
if (!arr || !arr.length) return 'none';
|
|
432
|
+
await clickAt(page, arr[0].x, arr[0].y);
|
|
433
|
+
await sleep(700);
|
|
434
|
+
return dismissBubbles(page, depth + 1);
|
|
341
435
|
}
|
|
342
436
|
|
|
343
437
|
// 列表第一行 = 最新创建的计划(列表按创建时间倒序)
|
|
@@ -395,7 +489,7 @@ async function addMaterialsViaDrawer(page, aavid, planId, names, opts = {}) {
|
|
|
395
489
|
if (!targets.length) throw new Error('找不到千川标签页');
|
|
396
490
|
// 绑定到当前驱动的那个标签页(有 id 就按 id,没有就按连接时的 URL 兜底)
|
|
397
491
|
const tgt = (page.id && targets.find((t) => t.id === page.id)) || targets.find((t) => t.url === page.url) || targets[0];
|
|
398
|
-
const res = await pickAllOnTarget(tgt, names);
|
|
492
|
+
const res = await pickAllOnTarget(tgt, names, opts.onlyIds, opts.onlyRows);
|
|
399
493
|
if (res.error) throw new Error(res.error);
|
|
400
494
|
mark('pick', JSON.stringify(res.log));
|
|
401
495
|
if (opts.cancelAfterPick) {
|
|
@@ -416,6 +510,15 @@ async function cmdMaterials() {
|
|
|
416
510
|
const p = paramsFile ? JSON.parse(fs.readFileSync(paramsFile, 'utf8')) : {};
|
|
417
511
|
const names = Object.values(p.awemeNames || {});
|
|
418
512
|
if (!names.length) throw new Error('params.json 里没有 awemeNames,拿不到抖音号名单');
|
|
513
|
+
const onlyMode = process.argv.includes('--only') || process.argv[6] === 'only';
|
|
514
|
+
let onlyIds = null;
|
|
515
|
+
let onlyRows = null;
|
|
516
|
+
if (onlyMode) {
|
|
517
|
+
const ml = Array.isArray(p.materialsList) ? p.materialsList : [];
|
|
518
|
+
onlyIds = ml.map((x) => String((x && x.id) || x)).filter(Boolean);
|
|
519
|
+
onlyRows = ml.map((x) => ({ img: String((x && x.img) || ''), row: String((x && x.row) || ''), aweme: String((x && x.aweme) || ''), awemeId: String((x && x.awemeId) || ''), date: String((x && x.date) || '') })).filter((x) => x.row || x.img);
|
|
520
|
+
if (!onlyIds.length) throw new Error('params.json 里没有 materialsList(先用带素材清单的 capture 抓一次)');
|
|
521
|
+
}
|
|
419
522
|
if (dry) {
|
|
420
523
|
const page0 = await connectFor(aavid);
|
|
421
524
|
mark('connected');
|
|
@@ -436,32 +539,40 @@ async function cmdMaterials() {
|
|
|
436
539
|
const prePick = ['nav-done','injected','page-ready','tabs','search-box','list-ready','search-unique','material-tab','drawer-material','material-src','material-type','popup','popup-offscreen'];
|
|
437
540
|
let res;
|
|
438
541
|
try {
|
|
439
|
-
res = await addMaterialsViaDrawer(page, aavid, planId, names, { cancelAfterPick: process.argv.includes('--picktest') });
|
|
542
|
+
res = await addMaterialsViaDrawer(page, aavid, planId, names, { cancelAfterPick: process.argv.includes('--picktest'), onlyIds, onlyRows });
|
|
440
543
|
} catch (e) {
|
|
544
|
+
if (String(e.message).indexOf('ONLY_MISSING') === 0) throw e;
|
|
441
545
|
if (prePick.indexOf(LAST) < 0) throw e;
|
|
442
546
|
mark('materials-retry', String(e.message).slice(0, 90));
|
|
443
547
|
const p2 = await reopenTab(aavid);
|
|
444
|
-
res = await addMaterialsViaDrawer(p2, aavid, planId, names, { cancelAfterPick: process.argv.includes('--picktest'), _reopened: true });
|
|
548
|
+
res = await addMaterialsViaDrawer(p2, aavid, planId, names, { cancelAfterPick: process.argv.includes('--picktest'), _reopened: true, onlyIds, onlyRows });
|
|
445
549
|
}
|
|
446
|
-
mark('result', JSON.stringify({ totalVideos: res.totalVideos, submitted: res.submitted, picktest: process.argv.includes('--picktest') }));
|
|
550
|
+
mark('result', JSON.stringify({ totalVideos: res.totalVideos, submitted: res.submitted, picktest: process.argv.includes('--picktest'), only: res.only || null }));
|
|
447
551
|
}
|
|
448
552
|
|
|
449
|
-
// 一条龙:新建 → 发布 →
|
|
553
|
+
// 一条龙:新建 → 发布 → 按计划名搜到新计划 → 详情抽屉加素材
|
|
450
554
|
async function searchByName(page, name) {
|
|
451
|
-
|
|
555
|
+
const okExpr = '(() => { const trs=[...document.querySelectorAll("tbody tr")].filter(r=>(r.innerText||"").indexOf("ID:")>=0); return trs.length===1 && (trs[0].innerText||"").indexOf(' + JSON.stringify(name) + ')>=0 })()'
|
|
556
|
+
const searchOnce = async () => {
|
|
452
557
|
await focusAndType(page, PLAN_SEARCH, name)
|
|
453
558
|
await sleep(700)
|
|
454
559
|
await pressEnter(page)
|
|
455
|
-
|
|
456
|
-
if (ok) return true
|
|
457
|
-
await sleep(800)
|
|
560
|
+
return await wait(page, okExpr, 8000)
|
|
458
561
|
}
|
|
459
|
-
return
|
|
562
|
+
if (await searchOnce()) return true
|
|
563
|
+
// 用户 2026-11-26:搜不到 → 刷新界面一次 → 再搜;仍搜不到就报异常,不做额外重试
|
|
564
|
+
mark('search-reload', 'once')
|
|
565
|
+
try { await page.eval('location.reload()') } catch (e) {}
|
|
566
|
+
await sleep(6000)
|
|
567
|
+
try { await page.eval(INJECT) } catch (e) {}
|
|
568
|
+
await sleep(1200)
|
|
569
|
+
return await searchOnce()
|
|
460
570
|
}
|
|
461
571
|
|
|
462
572
|
async function cmdAll() {
|
|
463
573
|
const aavid = process.argv[3], paramsFile = process.argv[4]
|
|
464
574
|
const argv0 = process.argv.slice(0, 2)
|
|
575
|
+
const onlyFlag = process.argv.includes('--only')
|
|
465
576
|
process.argv = argv0.concat(['create', aavid, paramsFile])
|
|
466
577
|
await cmdCreate()
|
|
467
578
|
process.argv = argv0.concat(['publish'])
|
|
@@ -475,18 +586,17 @@ async function cmdAll() {
|
|
|
475
586
|
await dismissBubbles(page)
|
|
476
587
|
mark('list-ready')
|
|
477
588
|
let newId = null, rowText = ''
|
|
478
|
-
for (let i = 0; i <
|
|
589
|
+
for (let i = 0; i < 1 && !newId; i++) {
|
|
479
590
|
const hit = await searchByName(page, wantName)
|
|
480
591
|
rowText = await page.eval('(() => { const trs=[...document.querySelectorAll("tbody tr")].filter(r=>(r.innerText||"").indexOf("ID:")>=0); return trs.length ? trs[0].innerText.replace(/\s+/g," ").trim() : "" })()')
|
|
481
592
|
const m = String(rowText).match(/ID[::]\s*(\d{10,})/)
|
|
482
593
|
if (hit && m) newId = m[1]
|
|
483
594
|
else { mark('new-plan-retry', i + ' ' + String(rowText).slice(0, 50)); await sleep(2000) }
|
|
484
595
|
}
|
|
485
|
-
if (!newId) { try { newId = await newestPlanId(page) } catch (e) {} }
|
|
486
596
|
if (!newId) throw new Error('发布后拿不到新计划 ID(按名字搜也没有)')
|
|
487
597
|
if (String(rowText).indexOf(wantName) < 0) throw new Error('搜到的不是刚建的计划(行=' + String(rowText).slice(0, 60) + ' 期望=' + wantName + ')')
|
|
488
598
|
mark('new-plan', newId + ' ' + wantName)
|
|
489
|
-
process.argv = argv0.concat(['materials', aavid, newId, paramsFile])
|
|
599
|
+
process.argv = argv0.concat(onlyFlag ? ['materials', aavid, newId, paramsFile, '--only'] : ['materials', aavid, newId, paramsFile])
|
|
490
600
|
await cmdMaterials()
|
|
491
601
|
}
|
|
492
602
|
|