| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- /**
- * 定点诊断:在**旧页面**的 fault 页签 DOM 里找 "前三" / "关键少数" 这类文本,打印其父元素 —— 弄清它们由谁产出。
- * 用法:node tools/probe_baseline.mjs fault 前三
- */
- import { JSDOM, VirtualConsole } from 'jsdom'
- const GATEWAY = 'http://127.0.0.1:28084'
- const TAB = process.argv[2] || 'fault'
- const NEEDLE = process.argv[3] || '前三'
- const html = await (await fetch(GATEWAY + '/detail/v2')).text()
- const dom = new JSDOM(html, {
- url: `${GATEWAY}/detail/v2#tab=${TAB}`, runScripts: 'dangerously', pretendToBeVisual: true,
- virtualConsole: new VirtualConsole(),
- beforeParse: (w) => {
- w.fetch = async (i, init) => {
- const raw = typeof i === 'string' ? i : i.url
- const u = raw.startsWith('http') ? raw : GATEWAY + (raw.startsWith('/') ? raw : '/' + raw)
- const r = await fetch(u, init)
- const b = await r.text()
- return { ok: r.ok, status: r.status, headers: { get: (k) => r.headers.get(k) }, json: async () => JSON.parse(b), text: async () => b }
- }
- },
- })
- const doc = dom.window.document
- for (let i = 0; i < 120; i++) {
- if (doc.querySelector('#root .page-head')) break
- await new Promise((r) => setTimeout(r, 500))
- }
- const walk = (n) => {
- for (const c of n.childNodes) {
- if (c.nodeType === 3 && c.textContent.includes(NEEDLE)) {
- const p = c.parentElement
- console.log(`文本: "${c.textContent.trim().slice(0, 60)}"`)
- console.log(` 父: <${p.tagName.toLowerCase()} class="${p.className}">`)
- console.log(` 父外框: ${p.outerHTML.slice(0, 300).replace(/\s+/g, ' ')}`)
- console.log('')
- } else if (c.nodeType === 1) walk(c)
- }
- }
- walk(doc.getElementById('root'))
|