25 lines
1.2 KiB
TypeScript
25 lines
1.2 KiB
TypeScript
import * as dotenv from 'dotenv';
|
|
import * as path from 'path';
|
|
dotenv.config({ path: path.resolve(__dirname, '../.env') });
|
|
import { createDriver } from '../drivers/factory';
|
|
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
|
|
(async () => {
|
|
const d = createDriver(); await d.createSession();
|
|
const names = new Set<string>();
|
|
await (d as any).goBackToHomepage?.(); await sleep(1500);
|
|
let last = ''; let same = 0;
|
|
for (let i = 0; i < 40; i++) {
|
|
const src = await d.getSource();
|
|
if (d.platform === 'android') {
|
|
for (const n of src.split('<')) { if (/resource-id="[^"]*\/(nameText|nameTextMeter)"/.test(n)) { const t = (n.match(/text="([^"]*)"/) || [])[1]; if (t && t.trim()) names.add(t.trim()); } }
|
|
} else {
|
|
for (const m of src.match(/XCUIElementTypeCell[^>]*?name="([^"]+)"/g) || []) { const t = (m.match(/name="([^"]+)"/) || [])[1]; if (t) names.add(t); }
|
|
}
|
|
if (src === last) { same++; if (same >= 2) break; } else { same = 0; } // 连续2次完全相同才算到底
|
|
last = src;
|
|
await d.scrollDown(900); await sleep(900);
|
|
}
|
|
console.log(`首页设备卡(${names.size}): ` + [...names].join(' | '));
|
|
await d.destroySession();
|
|
})().catch(e => { console.error('ERR', e.message); process.exit(1); });
|