From f05cddac22f6da714ea35e8a8e652fa92ba118f3 Mon Sep 17 00:00:00 2001 From: maogeigei Date: Tue, 1 Sep 2026 15:18:45 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E8=AF=A6=E6=83=85=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=8D=A1=E6=A0=87=E7=AD=BE=E8=A1=8C=E7=A7=BB=E5=88=B0?= =?UTF-8?q?=E6=9C=80=E5=90=8E=E4=B8=80=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mcn-work-shop/cdp-verify-tag-last.mjs | 76 +++++++++++++++++++ .../V1.0/mcn-work-shop/public/data-pages.js | 2 +- 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 project/短视频脚本创作/V1.0/mcn-work-shop/cdp-verify-tag-last.mjs diff --git a/project/短视频脚本创作/V1.0/mcn-work-shop/cdp-verify-tag-last.mjs b/project/短视频脚本创作/V1.0/mcn-work-shop/cdp-verify-tag-last.mjs new file mode 100644 index 0000000..8bc0a2e --- /dev/null +++ b/project/短视频脚本创作/V1.0/mcn-work-shop/cdp-verify-tag-last.mjs @@ -0,0 +1,76 @@ +/* cdp-verify-tag-last.mjs — 验证:视频信息卡标签行移到最后一行(09-01) */ +const CDP = 'http://127.0.0.1:9223'; +async function getWs(targetId) { + const tabs = await (await fetch(CDP + '/json')).json(); + const t = tabs.find((x) => x.id === targetId); + if (!t) throw new Error('target not found: ' + targetId); + return t.webSocketDebuggerUrl; +} +function cdp(ws, method, params = {}) { + return new Promise((resolve, reject) => { + const id = ++cdp._id; + const w = new WebSocket(ws); + const timer = setTimeout(() => { try { w.close(); } catch (e) {} reject(new Error('timeout: ' + method)); }, 30000); + w.onopen = () => w.send(JSON.stringify({ id, method, params })); + w.onmessage = (ev) => { + const m = JSON.parse(ev.data); + if (m.id !== id) return; + clearTimeout(timer); + try { w.close(); } catch (e) {} + m.error ? reject(new Error(method + ': ' + JSON.stringify(m.error))) : resolve(m.result); + }; + w.onerror = () => { clearTimeout(timer); reject(new Error('ws error: ' + method)); }; + }); +} +cdp._id = 0; +async function evalJs(ws, expr) { + const r = await cdp(ws, 'Runtime.evaluate', { expression: expr, awaitPromise: true, returnByValue: true }); + if (r.exceptionDetails) throw new Error('eval err: ' + JSON.stringify(r.exceptionDetails).slice(0, 300)); + return r.result && r.result.value; +} +const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); +const waitFor = async (ws, expr, timeout = 15000, label = '') => { + const t0 = Date.now(); + while (Date.now() - t0 < timeout) { + if (await evalJs(ws, expr)) return true; + await sleep(300); + } + throw new Error('waitFor timeout: ' + label); +}; + +async function main() { + const tabs = await (await fetch(CDP + '/json')).json(); + const tab = tabs.find((x) => x.url.includes('localhost:8900')) || tabs.find((x) => x.type === 'page'); + if (!tab) throw new Error('no 8900 tab found'); + const ws = await getWs(tab.id); + await cdp(ws, 'Page.enable'); + await cdp(ws, 'Runtime.enable'); + + let pass = 0, fail = 0; + const check = (name, cond, extra = '') => { cond ? pass++ : fail++; console.log((cond ? 'PASS' : 'FAIL') + ' | ' + name + (cond ? '' : ' ← ' + extra)); }; + + await cdp(ws, 'Page.navigate', { url: 'http://localhost:8900/?v=tl' + Date.now() + '#/video/680' }); + await waitFor(ws, `!!document.querySelector('.video-info')`, 15000, '视频详情渲染'); + + const r = await evalJs(ws, `(() => { + const card = document.querySelector('.video-info'); + const rows = card ? [...card.querySelectorAll('.info-row')] : []; + const labels = rows.map((r) => r.querySelector('.info-label') ? r.querySelector('.info-label').textContent.trim() : null); + const lastRow = rows[rows.length - 1]; + return { + labels, + lastLabel: labels[labels.length - 1], + lastRowHasLink: lastRow ? !!lastRow.querySelector('a.link') : false, + titleExists: !!card.querySelector('.info-card-title') + }; + })()`); + + check('信息卡共 3 行', r.labels.length === 3, '实际: ' + JSON.stringify(r.labels)); + check('行序 = 账号/点赞/标签', JSON.stringify(r.labels) === JSON.stringify(['账号', '点赞', '标签']), '实际: ' + JSON.stringify(r.labels)); + check('最后一行是标签且含查看视频链接', r.lastLabel === '标签' && r.lastRowHasLink); + check('信息卡标题仍存在', r.titleExists); + + console.log(`\nRESULT: ${pass}/${pass + fail}`); + process.exit(fail ? 1 : 0); +} +main().catch((e) => { console.error('ERROR', e.message); process.exit(1); }); diff --git a/project/短视频脚本创作/V1.0/mcn-work-shop/public/data-pages.js b/project/短视频脚本创作/V1.0/mcn-work-shop/public/data-pages.js index b40cf66..ce1c14c 100644 --- a/project/短视频脚本创作/V1.0/mcn-work-shop/public/data-pages.js +++ b/project/短视频脚本创作/V1.0/mcn-work-shop/public/data-pages.js @@ -546,9 +546,9 @@ async function renderVideoDetail(view, id) {
视频信息
-
${infoGrid('标签', `${v.tags ? esc(v.tags) : '无'} ${viewLink}`, true, true)}
${infoGrid('账号', v.account_name)}${infoGrid('视频ID', v.aweme_id)}${infoGrid('时长', fmtDuration(v.duration))}${infoGrid('发布时间', v.publish_time)}
${infoGrid('点赞', fmtWan(v.like_display || v.like_count))}${infoGrid('评论', fmtWan(v.comment_count))}${infoGrid('分享', fmtWan(v.share_count))}${infoGrid('收藏', fmtWan(v.collect_count))}
+
${infoGrid('标签', `${v.tags ? esc(v.tags) : '无'} ${viewLink}`, true, true)}
${tabBtns}
${body}