dsh-qianchuan-toolkit 1.0.21 → 1.0.35
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 +62 -0
- package/assets/live-control/scripts/account-lib.mjs +26 -10
- package/assets/live-control/scripts/cdp-lib.mjs +11 -4
- package/assets/live-control/scripts/hourly.mjs +48 -13
- package/assets/plan-copy/SKILL.md +21 -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 +44 -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 +63 -17
- 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/package.json +1 -1
|
@@ -14,7 +14,9 @@ import { pathToFileURL } from 'node:url'
|
|
|
14
14
|
// 5) 全部号点完,一次性点「确定」提交;不再二次进弹窗、不再翻抽屉核对
|
|
15
15
|
import fs from 'node:fs'
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// 复制技能固定连 9223 的独立浏览器实例(与 9222 的巡航实例物理隔离,互不抢标签)。
|
|
18
|
+
process.env.QC_CDP_PORT = process.env.QC_CDP_PORT || '9223'
|
|
19
|
+
const PORT = Number(process.env.QC_CDP_PORT || 9222), BASE = 'http://127.0.0.1:' + PORT
|
|
18
20
|
const OUT_DIR = process.env.QC_OUT || path.join(process.env.USERPROFILE || process.env.HOME || '.', '.qianchuan-cruise', 'out')
|
|
19
21
|
const CARD = '.main-vmok-plugin-create-material-list-card-item'
|
|
20
22
|
const NAV = '.main-vmok-plugin-tabs__nav-list'
|
|
@@ -52,6 +54,7 @@ const clickTab = (name) => `(()=>{const ls=[...document.querySelectorAll('${NAV}
|
|
|
52
54
|
// 只取真能被点到的卡片:弹窗 DOM 里有隐藏同构副本,坐标取自副本会点击落空或点穿页面
|
|
53
55
|
// 返回全部去重卡片 id(网格多行、可横向滚动;滚动与命中判定交给 cardPos)
|
|
54
56
|
const listCards = `(()=>{const seen=new Set();const out=[];for(const c of document.querySelectorAll('${CARD}')){const w=c.querySelector('[itemid]')||c;const id=w.getAttribute('itemid');if(!id||seen.has(id))continue;const r=c.getBoundingClientRect();if(r.width<10||r.height<10)continue;seen.add(id);out.push({id,y:Math.round(r.y),x:Math.round(r.x)})}out.sort((a,b)=>a.y-b.y||a.x-b.x);return out.map(o=>o.id)})()`
|
|
57
|
+
const allCards = '(()=>{const out=[];for(const c of document.querySelectorAll("' + CARD + '")){const w=c.querySelector("[itemid]")||c;const id=w.getAttribute("itemid");if(!id)continue;const r=c.getBoundingClientRect();if(r.width<10||r.height<10)continue;const im=c.querySelector("img");const src=im?String(im.src||""):"";const km=src.match(/tos-cn-[^\\/]+\\/([^~?]+)/);out.push([id,String(w.getAttribute("title")||""),km?km[1]:""])}return JSON.stringify(out)})()'
|
|
55
58
|
const chainInfo = (id) => `(()=>{const c=[...document.querySelectorAll('${CARD}')].map(x=>x).filter(x=>(x.querySelector('[itemid]')||x).getAttribute('itemid')===${JSON.stringify(id)})[0];if(!c)return null;const out=[];let a=c;for(let i=0;i<8&&a&&a!==document.body;i++,a=a.parentElement){const s=getComputedStyle(a);const r=a.getBoundingClientRect();out.push({t:a.tagName,c:String(a.className).slice(0,60),ox:s.overflowX,oy:s.overflowY,sl:a.scrollLeft,sw:a.scrollWidth,cw:a.clientWidth,x:Math.round(r.x),w:Math.round(r.width),tr:s.transform.slice(0,30)})}return out})()`
|
|
56
59
|
// 面板被渲染到视口右侧外(左边界≥innerWidth)时,强制 fixed 定位到屏幕内,避免点不到卡片
|
|
57
60
|
const fixOffscreen = `(()=>{const el=document.querySelector('.main-vmok-plugin-create-material-list');if(!el)return 'nolist';let a=el.offsetParent,tf=null;while(a&&a!==document.documentElement){const s=getComputedStyle(a);if(s.transform&&s.transform!=='none'){tf=a;break}a=a.offsetParent}if(!tf){let p=el.parentElement;while(p&&p!==document.documentElement){const s=getComputedStyle(p);if(s.transform&&s.transform!=='none'){tf=p;break}p=p.parentElement}}if(tf){tf.style.transform='none'}let r=el.getBoundingClientRect();if(!(r.x>=0&&r.x+40<innerWidth)){el.style.position='fixed';el.style.left='320px';el.style.top='60px';el.style.zIndex='99999';el.style.background='#fff';el.style.maxHeight=(innerHeight-90)+'px';el.style.overflow='auto'}const r2=el.getBoundingClientRect();return 'tf='+(tf?String(tf.className).slice(0,42):'none')+' x='+Math.round(r.x)+' -> '+Math.round(r2.x)})()`
|
|
@@ -109,13 +112,27 @@ async function selectCards(c, ids) {
|
|
|
109
112
|
const scrollStep = '(()=>{const roots=[...document.querySelectorAll("[class*=create-material]")];const els=new Set();for(const r of roots){let a=r;for(let i=0;i<8&&a;i++,a=a.parentElement)els.add(a)}let n=0;for(const el of els){if(el===document.body||el===document.documentElement)continue;const rc=el.getBoundingClientRect();if(!rc||rc.width<10)continue;const s=getComputedStyle(el);if((s.overflowX==="auto"||s.overflowX==="scroll")&&el.scrollWidth>el.clientWidth+4){el.scrollLeft=Math.min(el.scrollLeft+Math.round(el.clientWidth*0.8),el.scrollWidth-el.clientWidth);n++}if((s.overflowY==="auto"||s.overflowY==="scroll")&&el.scrollHeight>el.clientHeight+4&&el.clientHeight>200){el.scrollTop=Math.min(el.scrollTop+Math.round(el.clientHeight*0.6),el.scrollHeight-el.clientHeight);n++}}return n})()'
|
|
110
113
|
|
|
111
114
|
// 供 copy.mjs 复用:在已打开的「添加视频」弹窗里按名单逐个抖音号全选,返回结构化日志
|
|
112
|
-
export async function pickAllOnTarget(target, names) {
|
|
115
|
+
export async function pickAllOnTarget(target, names, onlyIds, onlyRows) {
|
|
116
|
+
const ONLY = Array.isArray(onlyIds) && onlyIds.length ? new Set(onlyIds.map(String)) : null
|
|
113
117
|
const c = await connect(target)
|
|
114
118
|
const modalOpen = await ev(c, `(()=>/已选择\\s*\\d+\\/200/.test(document.body.innerText))()`)
|
|
115
119
|
if (!modalOpen) return { error: '「添加视频」弹窗没开,先点「添加视频」' }
|
|
116
120
|
await ev(c, resetScroll)
|
|
117
121
|
|
|
118
122
|
const log = []
|
|
123
|
+
const matchedIds = new Set()
|
|
124
|
+
const matchedTitles = []
|
|
125
|
+
const OROWS = Array.isArray(onlyRows) ? onlyRows : []
|
|
126
|
+
const IMGS = new Set(OROWS.map((r) => (r && typeof r === 'object' ? String(r.img || '') : '')).filter(Boolean))
|
|
127
|
+
const WHITE = OROWS.map((r) => (r && typeof r === 'object' ? String(r.row || '') : String(r))).map((r) => r.replace(/[\s\u00a0]+/g, '')).filter(Boolean)
|
|
128
|
+
const USE_IMG = IMGS.size > 0
|
|
129
|
+
const DRY = process.env.QC_ONLY_DRYRUN === '1'
|
|
130
|
+
const DUMP = process.env.QC_DUMP_CARDS === '1'
|
|
131
|
+
const cardsAll = []
|
|
132
|
+
console.log('MATCH-MODE ' + (USE_IMG ? 'img' : 'title') + ' imgs=' + IMGS.size + ' rows=' + WHITE.length)
|
|
133
|
+
console.log('WHITE-SAMPLE ' + JSON.stringify(WHITE.slice(0, 2).map((t) => t.slice(0, 50))) + ' IMG-SAMPLE ' + JSON.stringify([...IMGS].slice(0, 2)))
|
|
134
|
+
let onlyClicked = 0
|
|
135
|
+
let onlyDiag = null
|
|
119
136
|
const fixRes = 'skip'
|
|
120
137
|
for (const name of names) {
|
|
121
138
|
let r = await ev(c, clickTab(name))
|
|
@@ -131,17 +148,106 @@ export async function pickAllOnTarget(target, names) {
|
|
|
131
148
|
if (t === 'OK') { refreshed = true; await sleep(1200); ids = await pollCards(c, 12000) }
|
|
132
149
|
}
|
|
133
150
|
const before = await ev(c, getSel)
|
|
151
|
+
if (DUMP) {
|
|
152
|
+
try {
|
|
153
|
+
const arr = JSON.parse(await ev(c, '(() => { const out = []; for (const c of document.querySelectorAll("' + CARD + '")) { const w = c.querySelector("[itemid]") || c; const id = w.getAttribute("itemid"); if (!id) continue; out.push([id, String(w.getAttribute("title") || ""), String(w.getAttribute("createtime") || ""), String(w.getAttribute("authoruid") || ""), String(w.getAttribute("awemeuid") || "")]) } return JSON.stringify(out) })()'))
|
|
154
|
+
for (const a of arr) cardsAll.push({ tab: name, id: a[0], title: a[1], createtime: a[2], authoruid: a[3], awemeuid: a[4] })
|
|
155
|
+
} catch (e) { console.log('DUMP-ERR ' + String(e.message).slice(0, 80)) }
|
|
156
|
+
}
|
|
134
157
|
let sel = { clicked: 0, retried: 0, skipped: 0, already: 0, unknown: [] }
|
|
135
|
-
if (
|
|
158
|
+
if (ONLY) {
|
|
159
|
+
const rowsTab = OROWS.filter((r0) => r0 && typeof r0 === 'object' && (String(r0.aweme || '') === name || String(r0.awemeId || '') === name))
|
|
160
|
+
const rowsUse = rowsTab.length ? rowsTab : OROWS
|
|
161
|
+
if (!rowsTab.length) console.log('FALLBACK-ALL ' + name)
|
|
162
|
+
const whiteTab = rowsUse.map((r0) => (r0 && typeof r0 === 'object' ? String(r0.row || '') : String(r0))).map((s) => s.replace(/[\s\u00a0]+/g, '')).filter(Boolean)
|
|
163
|
+
const r = await selectOnly(c, ONLY, whiteTab, 25000, IMGS, USE_IMG, DRY)
|
|
164
|
+
sel = { clicked: r.clicked, retried: 0, skipped: 0, already: 0, unknown: [], picked: r.picked }
|
|
165
|
+
onlyDiag = r.diag || null
|
|
166
|
+
for (const id of r.picked) matchedIds.add(String(id))
|
|
167
|
+
for (const t of r.pickedTitles) matchedTitles.push(t)
|
|
168
|
+
onlyClicked += r.clicked
|
|
169
|
+
await ev(c, resetScroll)
|
|
170
|
+
} else if (ids.length) sel = await selectCards(c, ids)
|
|
136
171
|
const after = await ev(c, getSel)
|
|
137
172
|
if (refreshed) { await ev(c, filterToggle); await sleep(600) }
|
|
138
173
|
log.push({ name, cards: ids.length, before, after, delta: after - before, clicked: sel.clicked, retried: sel.retried, already: sel.already, unknown: sel.unknown, skipped: sel.skipped, why: sel.why, pos: await ev(c, listPos), note: ids.length ? undefined : '该号主页无可投视频(取消过滤后仍为空)' })
|
|
139
174
|
}
|
|
175
|
+
if (DUMP) {
|
|
176
|
+
const fsmod = await import('node:fs')
|
|
177
|
+
fsmod.writeFileSync(process.env.QC_DUMP_FILE || 'cards-dump.json', JSON.stringify(cardsAll))
|
|
178
|
+
console.log('DUMP-WROTE ' + cardsAll.length)
|
|
179
|
+
}
|
|
180
|
+
let onlyInfo = null
|
|
181
|
+
if (ONLY) {
|
|
182
|
+
const matchedRows = WHITE.filter((r) => matchedTitles.some((t) => r.indexOf(t) >= 0))
|
|
183
|
+
const missRow = WHITE.filter((r) => matchedRows.indexOf(r) < 0)
|
|
184
|
+
const missId = WHITE.length ? [] : [...ONLY].filter((id) => !matchedIds.has(id))
|
|
185
|
+
onlyInfo = { want: WHITE.length || ONLY.size, matched: WHITE.length ? matchedRows.length : matchedIds.size, missing: missRow.slice(0, 10).map((r) => r.slice(0, 90)).concat(missId.slice(0, 10)), missingCount: missRow.length + missId.length, clicked: onlyClicked }
|
|
186
|
+
console.log('CARD-DIAG ' + JSON.stringify(onlyDiag))
|
|
187
|
+
try { console.log('SRC-OPTS ' + JSON.stringify(await ev(c, '(() => { const es = [...document.querySelectorAll("[class*=select],[class*=Select]")].map((e) => String(e.innerText || "").replace(/[\s]+/g, " ").trim()).filter((t) => t); return es.slice(0, 15) })()'))) } catch (e) { console.log('SRC-OPTS err ' + String(e.message).slice(0, 80)) }
|
|
188
|
+
if (onlyInfo.missingCount) console.log('ONLY-MISSING ' + onlyInfo.missingCount + ' ' + JSON.stringify(onlyInfo.missing))
|
|
189
|
+
}
|
|
190
|
+
if (DRY) {
|
|
191
|
+
const cx = await ev(c, '(() => { const bs = [...document.querySelectorAll("button")].filter((b) => b.innerText.trim() === "取消" && b.getBoundingClientRect().width > 0); if (!bs.length) return "NOCANCEL"; const r = bs[bs.length - 1].getBoundingClientRect(); return [Math.round(r.x + r.width / 2), Math.round(r.y + r.height / 2)] })()')
|
|
192
|
+
if (Array.isArray(cx)) { await click(c, cx[0], cx[1]); await sleep(800) }
|
|
193
|
+
return { ok: true, dryRun: true, submitted: false, only: onlyInfo, log }
|
|
194
|
+
}
|
|
140
195
|
const okb = await ev(c, `(()=>{const bs=[...document.querySelectorAll('button')].filter(b=>b.innerText.trim()==='确定'&&b.getBoundingClientRect().width>0);if(!bs.length)return 'NOOK';const r=bs[bs.length-1].getBoundingClientRect();return [Math.round(r.x+r.width/2),Math.round(r.y+r.height/2)]})()`)
|
|
141
196
|
let submitted = false
|
|
142
197
|
if (Array.isArray(okb)) { await click(c, okb[0], okb[1]); await sleep(5000); submitted = true }
|
|
143
198
|
const total = await ev(c, `(()=>{const m=document.body.innerText.match(/共\\d+个视频/);return m?m[0]:null})()`)
|
|
144
|
-
return { ok: true, fix: fixRes, submitted, totalVideos: total, log }
|
|
199
|
+
return { ok: true, fix: fixRes, submitted, totalVideos: total, only: onlyInfo, log }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function titleOf(id) {
|
|
203
|
+
return '(() => { const ws = [...document.querySelectorAll("' + CARD + '")].map((x) => x.querySelector("[itemid]")).filter((x) => x && x.getAttribute("itemid") === ' + JSON.stringify(String(id)) + '); if (!ws.length) return ""; return String(ws[0].getAttribute("title") || "").replace(/[\s\u00a0]+/g, "") })()'
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
async function selectOnly(c, ONLY, WHITE, maxMs, IMGS, USE_IMG, DRY) {
|
|
207
|
+
const seen = new Set(); const picked = new Set(); const pickedTitles = []; const sample = []; let clicked = 0; let idle = 0
|
|
208
|
+
const __report = () => { try { console.log('ONLY-SAMPLE ' + JSON.stringify(sample)) } catch (e) {} }
|
|
209
|
+
const t0 = Date.now()
|
|
210
|
+
while (Date.now() - t0 < maxMs && idle < 2) {
|
|
211
|
+
let ids = []
|
|
212
|
+
try { ids = await ev(c, listCards) } catch (e) { ids = [] }
|
|
213
|
+
let added = 0
|
|
214
|
+
for (const id of ids) if (!seen.has(id)) { seen.add(id); added++ }
|
|
215
|
+
const hits = []
|
|
216
|
+
if (WHITE.length) {
|
|
217
|
+
let pairs = []
|
|
218
|
+
try { pairs = JSON.parse(await ev(c, allCards)) } catch (e) { pairs = [] }
|
|
219
|
+
for (const pr of pairs) {
|
|
220
|
+
const id = pr[0]; const raw = String(pr[1] || '')
|
|
221
|
+
if (picked.has(id)) continue
|
|
222
|
+
const t = raw.replace(/[\s\u00a0]+/g, '')
|
|
223
|
+
if (sample.length < 6 && t) sample.push(t.slice(0, 60))
|
|
224
|
+
if (!t && !USE_IMG) continue
|
|
225
|
+
const hit = USE_IMG ? IMGS.has(String(pr[2] || '')) : WHITE.some((r) => r.indexOf(t) >= 0)
|
|
226
|
+
if (hit) hits.push([id, t])
|
|
227
|
+
}
|
|
228
|
+
} else if (ONLY) {
|
|
229
|
+
for (const id of ids) if (ONLY.has(String(id)) && !picked.has(id)) hits.push([id, ''])
|
|
230
|
+
}
|
|
231
|
+
for (const hp of hits) {
|
|
232
|
+
const id = hp[0]; const t = hp[1]
|
|
233
|
+
if (picked.has(id)) continue
|
|
234
|
+
if (!DRY) {
|
|
235
|
+
const p = await ev(c, cardPos(id))
|
|
236
|
+
if (!p || p.err || typeof p.x !== 'number') continue
|
|
237
|
+
if ((await ev(c, isSel(id))) !== 1) { await click(c, p.x, p.y); clicked++ }
|
|
238
|
+
} else clicked++
|
|
239
|
+
picked.add(id)
|
|
240
|
+
if (t) pickedTitles.push(t)
|
|
241
|
+
await sleep(120)
|
|
242
|
+
}
|
|
243
|
+
idle = added ? 0 : idle + 1
|
|
244
|
+
const moved = await ev(c, scrollStep)
|
|
245
|
+
await sleep(350)
|
|
246
|
+
if (!moved && !added) break
|
|
247
|
+
}
|
|
248
|
+
const diag = await ev(c, '(() => { const cards=[...document.querySelectorAll("' + CARD + '")].slice(0,3); return cards.map((c) => { const w=c.querySelector("[itemid]")||c; const attrs={}; for (const a of w.attributes) attrs[a.name]=String(a.value).slice(0,90); const img=c.querySelector("img"); return { itemid:w.getAttribute("itemid"), attrs, img:img?String(img.src).slice(0,180):null, text:(c.innerText||"").replace(/\s+/g," ").slice(0,120), html:String(c.outerHTML).slice(0,400) } }) })()')
|
|
249
|
+
console.log('ONLY-SAMPLE ' + JSON.stringify(sample))
|
|
250
|
+
return { clicked, seen: [...seen], picked: [...picked], pickedTitles, diag }
|
|
145
251
|
}
|
|
146
252
|
|
|
147
253
|
async function main() {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { connect, sleep, listPages } from '../../live-control/scripts/cdp-lib.mjs'
|
|
2
|
+
// 复制技能固定连 9223 的独立浏览器实例(与 9222 的巡航实例物理隔离,互不抢标签)。
|
|
3
|
+
process.env.QC_CDP_PORT = process.env.QC_CDP_PORT || '9223';
|
|
2
4
|
const A = process.argv[2], ID = process.argv[3]
|
|
3
5
|
const pages = await listPages()
|
|
4
6
|
const hit = pages.find(p => p.type==='page' && (p.url||'').indexOf('overall-prom')>=0 && (p.url||'').indexOf(A)>=0)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
rem ===== QianChuan COPY debug browser launcher (port 9223, separate instance) =====
|
|
3
|
+
rem This instance is dedicated to the plan-copy skill so it never fights the cruise tab on 9222.
|
|
4
|
+
rem port: 9223 profile: %USERPROFILE%\qc-chrome-copy Chrome first, Edge fallback
|
|
5
|
+
rem First run: log in to QianChuan in this window once; the login is kept in this profile.
|
|
6
|
+
setlocal
|
|
7
|
+
set "PORT=9223"
|
|
8
|
+
set "PROFILE=%USERPROFILE%\qc-chrome-copy"
|
|
9
|
+
|
|
10
|
+
curl -s -m 2 http://127.0.0.1:%PORT%/json/version >nul 2>&1
|
|
11
|
+
if not errorlevel 1 (
|
|
12
|
+
echo [QC-COPY] already listening on port %PORT%
|
|
13
|
+
exit /b 0
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
set "BROWSER=C:\Program Files\Google\Chrome\Application\chrome.exe"
|
|
17
|
+
if not exist "%BROWSER%" set "BROWSER=C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
|
|
18
|
+
if not exist "%BROWSER%" set "BROWSER=%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe"
|
|
19
|
+
if not exist "%BROWSER%" set "BROWSER=%ProgramFiles%\Microsoft\Edge\Application\msedge.exe"
|
|
20
|
+
if not exist "%BROWSER%" (
|
|
21
|
+
echo [QC-COPY] Chrome/Edge not found. Edit the BROWSER line in this file.
|
|
22
|
+
pause
|
|
23
|
+
exit /b 1
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
echo [QC-COPY] browser: %BROWSER%
|
|
27
|
+
echo [QC-COPY] profile: %PROFILE%
|
|
28
|
+
start "" "%BROWSER%" ^
|
|
29
|
+
--remote-debugging-port=%PORT% ^
|
|
30
|
+
--remote-allow-origins=* ^
|
|
31
|
+
--user-data-dir="%PROFILE%" ^
|
|
32
|
+
--no-first-run ^
|
|
33
|
+
--no-default-browser-check ^
|
|
34
|
+
--start-maximized ^
|
|
35
|
+
"https://qianchuan.jinritemai.com/login"
|
|
36
|
+
|
|
37
|
+
echo [QC-COPY] waiting for port %PORT% ...
|
|
38
|
+
for /l %%i in (1,1,40) do (
|
|
39
|
+
timeout /t 1 /nobreak >nul
|
|
40
|
+
curl -s -m 1 http://127.0.0.1:%PORT%/json/version >nul 2>&1
|
|
41
|
+
if not errorlevel 1 (
|
|
42
|
+
echo [QC-COPY] OK port %PORT% ready in %%i s
|
|
43
|
+
exit /b 0
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
echo [QC-COPY] FAILED: port not listening.
|
|
47
|
+
echo [QC-COPY] Hint: this profile runs in its own window; keep it open while copying.
|
|
48
|
+
pause
|
|
49
|
+
exit /b 1
|