const sleep = ms => new Promise(r => setTimeout(r, ms)); const propsOf = el => { for (const k of Object.keys(el)) if (k.startsWith('__reactProps$')) return el[k]; return null; }; const btn = (txt) => { for (const b of document.querySelectorAll('button')) if ((b.innerText||'').trim() === txt) return b; return null; }; const out = {}; out.pourBefore = (await eda.pcb_PrimitivePour.getAll()).length; out.pouredBefore = (await eda.pcb_PrimitivePoured.getAll()).length; const b = btn('重建所有'); if (!b) return {err: '没找到 重建所有 按钮 —— 铺铜管理器是不是关了?', out}; // 先试 React 的 onClick,不行再 native let fired = 'none'; const p = propsOf(b); if (p && typeof p.onClick === 'function') { p.onClick({target: b, currentTarget: b, stopPropagation(){}, preventDefault(){}, nativeEvent:{}, button:0, detail:1}); fired = 'react'; } else { b.click(); fired = 'native'; } out.fired = fired; // 等填充:每 2 s 看一次 poured 数,最多 90 s for (let i = 0; i < 45; i++) { await sleep(2000); const n = (await eda.pcb_PrimitivePoured.getAll()).length; if (n > out.pouredBefore) { out.pouredAfter = n; out.waitedS = (i+1)*2; break; } } if (out.pouredAfter === undefined) { out.pouredAfter = (await eda.pcb_PrimitivePoured.getAll()).length; out.waitedS = 90; } return out;