mirror of
https://github.com/refact0r/midnight-discord.git
synced 2026-11-27 08:03:34 +01:00
3 lines
999 B
JavaScript
3 lines
999 B
JavaScript
// usage (via cdp eval): dumps a compact DOM tree for a selector. node scripts/cdp.mjs eval "$(node scripts/dom.js '<selector>' [maxDepth] [maxLines])"
|
|
const [sel, depth = 12, lines = 120] = process.argv.slice(2);
|
|
console.log(`(() => { const root=document.querySelector(${JSON.stringify(sel)}); if(!root) return "no match"; const out=[]; const walk=(el,d)=>{ if(d>${depth}||out.length>${lines}) return; const r=el.getBoundingClientRect(); if(r.height<2&&r.width<2) return; const cls=[...el.classList].join("."); const t=el.children.length===0&&el.textContent?" \\""+el.textContent.trim().slice(0,24)+"\\"":""; out.push(" ".repeat(d)+el.tagName.toLowerCase()+(cls?"."+cls:"")+(el.id?"#"+el.id:"")+(el.getAttribute("aria-label")?"[aria-label="+el.getAttribute("aria-label").slice(0,20)+"]":"")+" "+Math.round(r.x)+","+Math.round(r.y)+" "+Math.round(r.width)+"x"+Math.round(r.height)+t); if(el.tagName!=="svg") for(const c of el.children) walk(c,d+1); }; walk(root,0); return out.join("\\n"); })()`);
|