// 验证王微斯卡片玫瑰金背景渲染(断言渐变 stop + 背景上文字提亮 + 截图) const list = await fetch('http://localhost:9223/json').then((r) => r.json()); let page = list.find((t) => t.type === 'page' && (decodeURIComponent(t.url).includes('王微斯') || t.url.includes('8899'))); if (!page) { console.log('ERR: no wangweisi/8899 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, 300) }; return r.result.value; }; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); await send('Page.enable'); await send('Runtime.enable'); const url = 'file:///C:/Users/maidou/Desktop/MCNSkill项目/王微斯/王微斯账号设定卡.svg'; await send('Page.navigate', { url }); await sleep(1200); await send('Page.reload', { ignoreCache: true }); await sleep(2500); const check = await ev(`(() => { const g = document.getElementById('bgGrad'); const stops = g ? g.querySelectorAll('stop') : []; const titles = [...document.querySelectorAll('text')].filter((t) => t.textContent.includes('▍')).map((t) => t.getAttribute('fill')); const deco = [...document.querySelectorAll('text')].find((t) => t.textContent.includes('channels requirement'))?.getAttribute('fill'); const copy = [...document.querySelectorAll('text')].filter((t) => t.textContent.includes('数据来源')).map((t) => t.getAttribute('fill')); const arrows = [...document.querySelectorAll('line')].map((l) => [Number(l.getAttribute('x1')), Number(l.getAttribute('x2'))]); return { bg0: stops[0]?.getAttribute('stop-color'), bg1: stops[1]?.getAttribute('stop-color'), titles, deco, copy, arrows, arrowsInGap: arrows.every(([a, b]) => b - a >= 11), // 线长≥11px(原 2px 贴卡) whiteCards: document.querySelectorAll('rect[fill="#FFFFFF"]').length, pinkChips: document.querySelectorAll('rect[fill="#F7E8F2"]').length }; })()`); console.log(JSON.stringify(check, null, 2)); const r = await send('Page.captureScreenshot', { format: 'png' }); const fs = await import('node:fs'); fs.writeFileSync('shot-wangweisi-rosegold.png', Buffer.from(r.data, 'base64')); console.log('截图完成: shot-wangweisi-rosegold.png'); ws.close();