视频详情信息卡顶部加标题「视频信息」(带分隔线)
This commit is contained in:
1 parent
6dd0519c84
commit
8dcbdf6054
3 files changed
+78
No files matched your search
@@ -0,0 +1,76 @@
|
||||
/* cdp-verify-infocard-title.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=ic' + Date.now() + '#/video/680' });
|
||||
await waitFor(ws, `!!document.querySelector('.video-info')`, 15000, '视频详情渲染');
|
||||
|
||||
const r = await evalJs(ws, `(() => {
|
||||
const card = document.querySelector('.video-info');
|
||||
const titleEl = card ? card.querySelector('.info-card-title') : null;
|
||||
const rows = card ? [...card.querySelectorAll('.info-row')] : [];
|
||||
return {
|
||||
hasTitle: !!titleEl,
|
||||
titleText: titleEl ? titleEl.textContent.trim() : null,
|
||||
rowCount: rows.length,
|
||||
firstLabel: rows[0] ? rows[0].querySelector('.info-label').textContent.trim() : null,
|
||||
hasBorder: titleEl ? getComputedStyle(titleEl).borderBottomWidth !== '0px' : false
|
||||
};
|
||||
})()`);
|
||||
|
||||
check('信息卡内存在标题元素 .info-card-title', r.hasTitle);
|
||||
check('标题文案 = 视频信息', r.titleText === '视频信息', '实际: ' + r.titleText);
|
||||
check('标题位于首行(标签)之前', r.hasTitle && r.firstLabel === '标签' && r.rowCount === 3, `rows=${r.rowCount}`);
|
||||
check('标题带分隔线样式', r.hasBorder);
|
||||
|
||||
console.log(`\nRESULT: ${pass}/${pass + fail}`);
|
||||
process.exit(fail ? 1 : 0);
|
||||
}
|
||||
main().catch((e) => { console.error('ERROR', e.message); process.exit(1); });
|
||||
@@ -545,6 +545,7 @@ async function renderVideoDetail(view, id) {
|
||||
<div class="page-toolbar">${toolbarBack()}<span class="page-title">${esc(cleanTitle(v.video_title) || '视频详情')}</span></div>
|
||||
<div class="detail-body">
|
||||
<div class="info-card video-info">
|
||||
<div class="info-card-title">视频信息</div>
|
||||
<div class="info-row">${infoGrid('标签', `${v.tags ? esc(v.tags) : '无'} ${viewLink}`, true, true)}</div>
|
||||
<div class="info-row">${infoGrid('账号', v.account_name)}${infoGrid('视频ID', v.aweme_id)}${infoGrid('时长', fmtDuration(v.duration))}${infoGrid('发布时间', v.publish_time)}</div>
|
||||
<div class="info-row">${infoGrid('点赞', fmtWan(v.like_display || v.like_count))}${infoGrid('评论', fmtWan(v.comment_count))}${infoGrid('分享', fmtWan(v.share_count))}${infoGrid('收藏', fmtWan(v.collect_count))}</div>
|
||||
|
||||
@@ -367,6 +367,7 @@ td.td-title { max-width: 240px; }
|
||||
|
||||
/* ================= 信息卡 ================= */
|
||||
.info-card { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; background: var(--panel); }
|
||||
.info-card-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
|
||||
/* 账号信息按行分组:行内项目按内容宽度左对齐,保留行间距 */
|
||||
.info-row { display: flex; flex-wrap: wrap; gap: 10px 80px; }
|
||||
.info-row .info-item { flex: 0 0 auto; min-width: 100px; }
|
||||
|
||||
Reference in new issue
Block a user