Files
dianxiaomi-crossborder-play…/妙手建品/ms_login.mjs
T

37 lines
2.5 KiB
JavaScript

import { listPages, wait } from '/home/admin9webs/shein建品/sh_lib.mjs';
import { CDP, SAN as S } from '/tmp/cdp3.mjs';
import { readFileSync } from 'fs';
// 凭据来自舰队技能档 agent-a2-import/skills/ecommerce/miaoshou-erp/SKILL.md(不回显)
const doc = readFileSync('/home/admin9webs/agent-a2-import/skills/ecommerce/miaoshou-erp/SKILL.md','utf8');
const acc = (doc.match(/xiaochaoren\d+/) || [])[0];
const pwd = (doc.match(/Bingo\d+@/) || [])[0];
console.log('账号:', acc ? acc.slice(0,4)+'***' : '未解析到', ' 密码:', pwd ? '已解析' : '未解析');
if(!acc || !pwd){ console.log('凭据解析失败,放弃登录'); process.exit(1); }
const t = (await listPages()).find(x=>/91miaoshou/i.test(x.url));
if(!t){ console.log('无妙手标签'); process.exit(1); }
const c = await CDP.connect(t.webSocketDebuggerUrl);
await c.send('Page.enable'); await c.send('Runtime.enable');
await wait(1500);
const filled = await c.evalJS(`(()=>{
const set=(sel,v)=>{const el=document.querySelector(sel); if(!el) return 0;
const setter=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,'value').set;
setter.call(el,v); el.dispatchEvent(new Event('input',{bubbles:true})); el.dispatchEvent(new Event('change',{bubbles:true}));
el.dispatchEvent(new KeyboardEvent('keyup',{bubbles:true})); return 1;};
const a=set('.account-input', ${JSON.stringify(acc)});
const p=set('.password-input', ${JSON.stringify(pwd)});
const captcha=document.querySelector('.captcha-text');
return JSON.stringify({account:a, password:p, hasCaptcha:!!captcha, hasBtn:!!document.querySelector('.login-button')});})()`);
console.log('填表:', S(String(filled)).slice(0,200));
await wait(600);
const clicked = await c.evalJS(`(()=>{const b=document.querySelector('.login-button'); if(!b) return 'no-btn';
for(const ev of ['mousedown','mouseup','click']) b.dispatchEvent(new MouseEvent(ev,{bubbles:true,cancelable:true,view:window})); return 'clicked';})()`);
console.log('提交:', String(clicked));
await wait(10000);
const after = await c.evalJS(`(()=>{const err=[...document.querySelectorAll('*')].filter(e=>e.children.length===0&&/错误|失败|验证码|锁定/.test(e.innerText||'')).map(e=>(e.innerText||'').trim()).slice(0,3);
return JSON.stringify({href:location.href, title:document.title, login:!!document.querySelector('input[type=password]'), err});})()`);
console.log('结果:', S(String(after)).slice(0,400));
try{ await c.shot('/tmp/ms_login.jpg'); console.log('shot ok'); }catch(e){}
process.exit(0);