Files
mcn-short-video/project/短视频脚本创作/V1.0/mcn-workshop/cdp-verify-btnwhite.mjs
T

36 lines
2.6 KiB
JavaScript
Raw Normal View History

// 验证:周榜功能列按钮统一「白底带边框」(btn-view / btn-import)
const list = await fetch('http://localhost:9223/json').then((r) => r.json());
let page = list.find((t) => t.type === 'page' && t.url.includes('localhost:8899'));
if (!page) { console.log('ERR: no workbuddy page open'); process.exit(1); }
const ws = new WebSocket(page.webSocketDebuggerUrl);
let id = 0; const pending = new Map();
const send = (method, params = {}) => new Promise((res, rej) => { const i = ++id; pending.set(i, { res, rej }); ws.send(JSON.stringify({ id: i, method, params })); });
ws.onmessage = (e) => { const m = JSON.parse(e.data); if (m.id && pending.has(m.id)) { const p = pending.get(m.id); pending.delete(m.id); m.error ? p.rej(new Error(m.error.message)) : p.res(m.result); } };
await new Promise((r) => (ws.onopen = r));
const ev = async (expr) => { const r = await send('Runtime.evaluate', { expression: expr, returnByValue: true, awaitPromise: true }); if (r.exceptionDetails) return { __err: (r.exceptionDetails.exception?.description || r.exceptionDetails.text).slice(0, 200) }; return r.result.value; };
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
await send('Page.enable'); await send('Runtime.enable');
const goto = async (hash) => { await send('Page.navigate', { url: 'http://localhost:8899/' + hash }); await sleep(1500); await send('Page.reload', { ignoreCache: true }); await sleep(3000); };
// 1) 功能页 #/ranking:查看 + 分析按钮
await goto('#/ranking');
const rank = await ev(`(() => {
const btns = [...document.querySelectorAll('.table tbody .cell-act .btn')];
return btns.slice(0, 4).map((b) => ({ txt: b.textContent.trim(), bg: getComputedStyle(b).backgroundColor, border: getComputedStyle(b).borderTopColor, color: getComputedStyle(b).color }));
})()`);
console.log('【功能页功能列】');
for (const b of rank) console.log(' ', b.txt, '| bg:', b.bg, '| border:', b.border);
// 2) 首页预览:查看 + 关注按钮
await goto('#/');
const home = await ev(`(() => {
const btns = [...document.querySelectorAll('#rankPreviewList .rank-row:not(.rank-head) .rk-act .btn')];
return btns.slice(0, 4).map((b) => ({ txt: b.textContent.trim(), bg: getComputedStyle(b).backgroundColor, border: getComputedStyle(b).borderTopColor }));
})()`);
console.log('【首页预览功能列】');
for (const b of home) console.log(' ', b.txt, '| bg:', b.bg, '| border:', b.border);
const allBtns = [...rank, ...home];
const ok = allBtns.length > 0 && allBtns.every((b) => b.bg === 'rgb(255, 255, 255)' && b.border !== 'rgb(245, 246, 248)');
console.log(ok ? 'PASS: 全部白底带边框' : 'CHECK');
ws.close();