46 lines
3.8 KiB
JavaScript
46 lines
3.8 KiB
JavaScript
import { newPage, closePage, wait } from '/home/admin9webs/shein建品/sh_lib.mjs';
|
|
import { SAN as S } from '/tmp/cdp3.mjs';
|
|
const P = `document.querySelector('#app').__vue_app__.config.globalProperties.$pinia`;
|
|
const c = await newPage('https://www.dianxiaomi.com/web/joomProduct/add');
|
|
await wait(12000);
|
|
await c.evalJS(`(()=>{const it=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).find(e=>/店铺名称/.test((e.querySelector('label')||{}).innerText||''));
|
|
const w=[...it.querySelectorAll('.ant-checkbox-wrapper')].find(x=>{const t=(x.innerText||'').trim(); return t&&!/^全部/.test(t);});
|
|
for(const ev of ['mousedown','mouseup','click']) w.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window}));
|
|
const i=w.querySelector('input'); if(i&&!i.checked) i.click(); return 1;})()`);
|
|
await wait(6000);
|
|
// 类目
|
|
const pos = JSON.parse(String(await c.evalJS(`(()=>{const it=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).find(e=>/产品分类/.test((e.querySelector('label')||{}).innerText||''));
|
|
const s=it.querySelector('.ant-select-selector'); s.scrollIntoView({block:'center'}); const r=s.getBoundingClientRect();
|
|
return JSON.stringify([Math.round(r.x+r.width/2),Math.round(r.y+r.height/2)]);})()`)));
|
|
await c.send('Input.dispatchMouseEvent',{type:'mouseMoved',x:pos[0],y:pos[1],buttons:0}); await wait(250);
|
|
for(const t of ['mousePressed','mouseReleased']) await c.send('Input.dispatchMouseEvent',{type:t,x:pos[0],y:pos[1],button:'left',clickCount:1,buttons:1});
|
|
await wait(1500);
|
|
await c.send('Input.insertText',{text:'发夹'}).catch(()=>{});
|
|
await wait(2500);
|
|
await c.evalJS(`(()=>{const dd=[...document.querySelectorAll('.ant-select-dropdown')].filter(e=>e.offsetParent!==null).pop();
|
|
const op=[...dd.querySelectorAll('.ant-select-item-option')][0]; const r=op.getBoundingClientRect();
|
|
for(const ev of ['mousedown','mouseup','click']) op.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window,clientX:r.x+r.width/2,clientY:r.y+r.height/2})); return 1;})()`);
|
|
await wait(6000);
|
|
// 在标题输入框里打字(走真实键盘)
|
|
const tpos = JSON.parse(String(await c.evalJS(`(()=>{const it=[...document.querySelectorAll('.ant-form-item')].filter(e=>e.offsetParent!==null).find(e=>/^\\s*\\*?产品标题/.test((e.innerText||'').trim()));
|
|
const inp=it?it.querySelector('input,textarea'):null; if(!inp) return '[]'; inp.scrollIntoView({block:'center'});
|
|
inp.setAttribute('data-probe','1'); const r=inp.getBoundingClientRect();
|
|
return JSON.stringify([Math.round(r.x+r.width/2),Math.round(r.y+r.height/2)]);})()`)));
|
|
console.log('标题框坐标:', JSON.stringify(tpos));
|
|
for(const t of ['mousePressed','mouseReleased']) await c.send('Input.dispatchMouseEvent',{type:t,x:tpos[0],y:tpos[1],button:'left',clickCount:1,buttons:1});
|
|
await wait(400);
|
|
await c.send('Input.insertText',{text:'PROBE-TITLE-XYZ'}).catch(()=>{});
|
|
await wait(2500);
|
|
// 全 store 搜索这个字符串
|
|
const found = await c.evalJS(`(()=>{const p=${P}; const needle='PROBE-TITLE-XYZ'; const hits=[];
|
|
const ids=(p._s instanceof Map?[...p._s.keys()]:Object.keys(p._s));
|
|
for(const id of ids){ try{ const s=(p._s.get?p._s.get(id):p._s[id]).$state;
|
|
const js=JSON.stringify(s); if(js&&js.includes(needle)) hits.push(id+':'+js.slice(Math.max(0,js.indexOf(needle)-70), js.indexOf(needle)+40).replace(/\\\\/g,'')); }catch(e){} }
|
|
const domVal=(document.querySelector('input[data-probe="1"]')||{}).value||'';
|
|
// joomAddStore 的非 $state 属性
|
|
let extra=[];
|
|
try{ const st=p._s.get('joomAddStore'); extra=Object.keys(st).filter(k=>k!=='$state'&&k!=='_s'&&!/^\\$/.test(k)).slice(0,18); }catch(e){}
|
|
return JSON.stringify({hits, domVal, joomAddStoreOwnKeys:extra});})()`);
|
|
console.log('命中:', S(String(found)).slice(0,1600));
|
|
await closePage(c); process.exit(0);
|