cursor-switch 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +16 -0
- package/dist/core/dashboard-launcher.d.ts +4 -4
- package/dist/core/dashboard-launcher.js +9 -9
- package/dist/core/outlook-launcher.d.ts +4 -0
- package/dist/core/outlook-launcher.js +162 -134
- package/dist/core/pure-login-service.d.ts +22 -2
- package/dist/core/pure-login-service.js +165 -72
- package/dist/core/welcome-offer-service.d.ts +52 -0
- package/dist/core/welcome-offer-service.js +369 -0
- package/dist/menu.js +14 -4
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -23,6 +23,7 @@ import { formatPlanName, formatPlanBadge } from './utils/plan-formatter.js';
|
|
|
23
23
|
import { runInteractiveMenu, handleAccountCleanupMenu } from './menu.js';
|
|
24
24
|
import { RefundService } from './core/refund-service.js';
|
|
25
25
|
import { PureLoginService } from './core/pure-login-service.js';
|
|
26
|
+
import { WelcomeOfferService } from './core/welcome-offer-service.js';
|
|
26
27
|
import { UpdateChecker, CURRENT_VERSION } from './core/update-checker.js';
|
|
27
28
|
import boxen from 'boxen';
|
|
28
29
|
import { copyToClipboard } from './utils/clipboard.js';
|
|
@@ -239,6 +240,21 @@ export function createCli() {
|
|
|
239
240
|
const pureService = new PureLoginService();
|
|
240
241
|
await pureService.runInteractiveFlow(store, storage, sqlite, paths.executablePath);
|
|
241
242
|
});
|
|
243
|
+
// 4.15 offer (老用户回归特权检测与免密直通)
|
|
244
|
+
program
|
|
245
|
+
.command('offer [identifier]')
|
|
246
|
+
.alias('welcome-back')
|
|
247
|
+
.alias('winback')
|
|
248
|
+
.description('检测老号是否命中 Cursor 回归特权优惠 (Welcome-Back Offer),支持传 Token 或邮箱密码代登')
|
|
249
|
+
.option('-t, --token <token>', '直接指定 SessionToken 进行检测')
|
|
250
|
+
.action(async (identifier, options) => {
|
|
251
|
+
const paths = resolveCursorPaths();
|
|
252
|
+
const storage = new StorageBridge(paths.storageJson);
|
|
253
|
+
const sqlite = new SqliteBridge(paths.sqliteDb);
|
|
254
|
+
const store = new AccountStore();
|
|
255
|
+
const input = options?.token || identifier;
|
|
256
|
+
await WelcomeOfferService.runInteractiveFlow(store, storage, sqlite, paths.executablePath, input);
|
|
257
|
+
});
|
|
242
258
|
// 4.2 oauth (全新无痕浏览器官方 OAuth 网页登录)
|
|
243
259
|
program
|
|
244
260
|
.command('oauth')
|
|
@@ -20,15 +20,15 @@ export declare class DashboardLauncher {
|
|
|
20
20
|
*/
|
|
21
21
|
static openDashboard(account: AccountInfo, options?: Partial<DashboardOpenOptions>): Promise<boolean>;
|
|
22
22
|
/**
|
|
23
|
-
* 直接通过 Token 凭据免密打开 Cursor
|
|
23
|
+
* 直接通过 Token 凭据免密打开 Cursor 官网后台或指定页面
|
|
24
24
|
*/
|
|
25
|
-
static openDashboardWithToken(token: string, email?: string, cdpPort?: number): Promise<boolean>;
|
|
25
|
+
static openDashboardWithToken(token: string, email?: string, cdpPort?: number, targetUrl?: string): Promise<boolean>;
|
|
26
26
|
/**
|
|
27
27
|
* 核心逻辑:优先使用原生 CDP 独立浏览器免密注入,优雅降级到 Python 或默认浏览器
|
|
28
28
|
*/
|
|
29
29
|
private static openWithCdpOrFallback;
|
|
30
30
|
/**
|
|
31
|
-
* 使用原生 CDP 启动独立 Chromium 浏览器并注入 Cookie
|
|
31
|
+
* 使用原生 CDP 启动独立 Chromium 浏览器并注入 Cookie 直达后台或指定页面
|
|
32
32
|
*/
|
|
33
|
-
static openWithCdp(token: string, email: string, existingCdpPort?: number): Promise<boolean>;
|
|
33
|
+
static openWithCdp(token: string, email: string, existingCdpPort?: number, targetUrl?: string): Promise<boolean>;
|
|
34
34
|
}
|
|
@@ -41,21 +41,21 @@ export class DashboardLauncher {
|
|
|
41
41
|
return this.openWithCdpOrFallback(sessionToken, email, options.cdpPort);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* 直接通过 Token 凭据免密打开 Cursor
|
|
44
|
+
* 直接通过 Token 凭据免密打开 Cursor 官网后台或指定页面
|
|
45
45
|
*/
|
|
46
|
-
static async openDashboardWithToken(token, email = 'Token User', cdpPort) {
|
|
47
|
-
return this.openWithCdpOrFallback(token.trim(), email, cdpPort);
|
|
46
|
+
static async openDashboardWithToken(token, email = 'Token User', cdpPort, targetUrl = 'https://cursor.com/cn/dashboard') {
|
|
47
|
+
return this.openWithCdpOrFallback(token.trim(), email, cdpPort, targetUrl);
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* 核心逻辑:优先使用原生 CDP 独立浏览器免密注入,优雅降级到 Python 或默认浏览器
|
|
51
51
|
*/
|
|
52
|
-
static async openWithCdpOrFallback(sessionToken, email, cdpPort) {
|
|
53
|
-
const dashboardUrl =
|
|
52
|
+
static async openWithCdpOrFallback(sessionToken, email, cdpPort, targetUrl = 'https://cursor.com/cn/dashboard') {
|
|
53
|
+
const dashboardUrl = targetUrl;
|
|
54
54
|
const cleanToken = (sessionToken || '').trim().replace(/["\r\n]/g, '');
|
|
55
55
|
// 1. 优先尝试:使用原生 CDP 引擎免密直达 (纯 Node.js,零依赖,秒开)
|
|
56
56
|
if (cleanToken) {
|
|
57
57
|
try {
|
|
58
|
-
const cdpSuccess = await this.openWithCdp(cleanToken, email, cdpPort);
|
|
58
|
+
const cdpSuccess = await this.openWithCdp(cleanToken, email, cdpPort, targetUrl);
|
|
59
59
|
if (cdpSuccess) {
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
@@ -113,9 +113,9 @@ export class DashboardLauncher {
|
|
|
113
113
|
return opened;
|
|
114
114
|
}
|
|
115
115
|
/**
|
|
116
|
-
* 使用原生 CDP 启动独立 Chromium 浏览器并注入 Cookie
|
|
116
|
+
* 使用原生 CDP 启动独立 Chromium 浏览器并注入 Cookie 直达后台或指定页面
|
|
117
117
|
*/
|
|
118
|
-
static async openWithCdp(token, email, existingCdpPort) {
|
|
118
|
+
static async openWithCdp(token, email, existingCdpPort, targetUrl = 'https://cursor.com/cn/dashboard') {
|
|
119
119
|
const installed = findInstalledBrowsers();
|
|
120
120
|
const chrome = installed.find((b) => b.name.includes('Chrome'));
|
|
121
121
|
const edge = installed.find((b) => b.name.includes('Edge'));
|
|
@@ -127,7 +127,7 @@ export class DashboardLauncher {
|
|
|
127
127
|
if (!selectedBrowser || !fs.existsSync(selectedBrowser.path)) {
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
|
-
const dashboardUrl =
|
|
130
|
+
const dashboardUrl = targetUrl;
|
|
131
131
|
let cdpPort = existingCdpPort;
|
|
132
132
|
let isNewInstance = false;
|
|
133
133
|
if (!cdpPort) {
|
|
@@ -49,6 +49,10 @@ export declare class OutlookLauncher {
|
|
|
49
49
|
static printResultCard(result: MailboxOpenResult): void;
|
|
50
50
|
/**
|
|
51
51
|
* 在已到达 Outlook 收件箱页面时,利用 CDP 实时嗅探 Cursor / WorkOS 最新的 6 位数字验证码
|
|
52
|
+
* 增强特性:
|
|
53
|
+
* 1. 自动识别并无感切换【重点 / 其他 (Other)】选项卡,彻底击破微软邮件分类盲区
|
|
54
|
+
* 2. 毫秒级匹配邮件列表项预览摘要 (如 "Your one-time code is 298372"),无需等待正文复杂渲染
|
|
55
|
+
* 3. 兼容卡片大字号、iframe 嵌套及多语系正则提取,捕获即完成
|
|
52
56
|
*/
|
|
53
57
|
static sniffVerificationCode(cdp: CdpEngine, timeoutMs?: number): Promise<string | null>;
|
|
54
58
|
}
|
|
@@ -316,19 +316,36 @@ export class OutlookLauncher {
|
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
|
-
// 状态 5
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (clickedSwitch) {
|
|
324
|
-
console.log(chalk.cyan(' → 检测到页面提供“使用密码”入口,已自动点击切换到密码登录...'));
|
|
319
|
+
// 状态 5: 智能切换为密码登录(优先寻找“使用密码”或“其他方式”,尽最大可能全自动完成登录)
|
|
320
|
+
if (!passwordFilled && usePasswordAttempts < 2) {
|
|
321
|
+
const switchRes = await this.tryClickUsePassword(cdp);
|
|
322
|
+
if (switchRes.clicked) {
|
|
325
323
|
usePasswordAttempts++;
|
|
326
|
-
|
|
327
|
-
await new Promise((r) => setTimeout(r,
|
|
328
|
-
continue;
|
|
324
|
+
console.log(chalk.cyan(` → 检测到页面提供“${switchRes.type === 'password' ? '使用密码' : '其他登录方式'}”入口,已尝试自动点击切换 (尝试 ${usePasswordAttempts}/2)...`));
|
|
325
|
+
await new Promise((r) => setTimeout(r, 1200));
|
|
326
|
+
continue; // 继续下一轮状态机,优先检查密码输入框是否已出现 (状态 3)
|
|
329
327
|
}
|
|
330
328
|
}
|
|
331
|
-
// 状态 6:
|
|
329
|
+
// 状态 6: 辅助邮箱 / 安全验证 / MFA 阻断检测
|
|
330
|
+
// 关键逻辑:仅在【无法切换密码】(已尝试 2 次切换未果,或页面无任何密码通道)时,才置顶交接给用户
|
|
331
|
+
const isSecurityProofUrl = curUrl.includes('/proofs/add') || curUrl.includes('/proofs/manage') || curUrl.includes('/proofs') || curUrl.includes('login.live.com/ppsecure');
|
|
332
|
+
const hasSecurityMarker = securityBlockerMarkers.some((m) => bodyLower.includes(m));
|
|
333
|
+
const hasMaskedEmail = /[a-z0-9._%+-]*\*{3,}@[a-z0-9.-]+/i.test(bodyText);
|
|
334
|
+
if (isSecurityProofUrl || (hasSecurityMarker && (hasMaskedEmail || curUrl.includes('login.live.com')))) {
|
|
335
|
+
if (!hasPwdInput) {
|
|
336
|
+
console.log(chalk.yellow(' → 该账号已被微软强制要求辅助邮箱验证 (无可用直接密码通道),已置顶浏览器交接...'));
|
|
337
|
+
await cdp.bringToFront();
|
|
338
|
+
cdp.disconnect();
|
|
339
|
+
return {
|
|
340
|
+
success: true,
|
|
341
|
+
email,
|
|
342
|
+
status: 'manual_required',
|
|
343
|
+
profileDir,
|
|
344
|
+
message: '微软强制要求辅助邮箱验证,当前页面无可用直接密码通道,已为您置顶浏览器窗口,请手动完成验证。',
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
// 状态 7: 保持登录状态 (KMSI - Keep Me Signed In) 页面 -> 自动点击“是”
|
|
332
349
|
const isKmsi = await cdp.evaluate(`(() => {
|
|
333
350
|
const text = (document.body && document.body.innerText || '').toLowerCase();
|
|
334
351
|
return text.includes('保持登录状态') || text.includes('stay signed in') || text.includes('stay sign in');
|
|
@@ -341,7 +358,7 @@ export class OutlookLauncher {
|
|
|
341
358
|
continue;
|
|
342
359
|
}
|
|
343
360
|
}
|
|
344
|
-
// 状态
|
|
361
|
+
// 状态 7.5: 微软服务协议与条款更新 (TOU - Terms of Use) 确认页 -> 自动点击“下一步” / “接受”
|
|
345
362
|
const isTou = curUrl.includes('/tou/') ||
|
|
346
363
|
curUrl.includes('/tou') ||
|
|
347
364
|
bodyLower.includes('更新条款') ||
|
|
@@ -356,39 +373,6 @@ export class OutlookLauncher {
|
|
|
356
373
|
continue;
|
|
357
374
|
}
|
|
358
375
|
}
|
|
359
|
-
// 状态 7: 辅助邮箱 / 安全验证 / MFA 敏感阻断检测
|
|
360
|
-
// 关键逻辑:只有在【确认无法切换为密码登录】(页面无“使用密码”按钮,或已提交密码后要求验证码)时,才停下交接给用户!
|
|
361
|
-
const isSecurityProofUrl = curUrl.includes('/proofs/add') || curUrl.includes('/proofs/manage') || curUrl.includes('/proofs');
|
|
362
|
-
const hasSecurityMarker = securityBlockerMarkers.some((m) => bodyLower.includes(m));
|
|
363
|
-
const hasMaskedEmail = /[a-z0-9._%+-]*\*{3,}@[a-z0-9.-]+/i.test(bodyText);
|
|
364
|
-
if (isSecurityProofUrl || (hasSecurityMarker && (hasMaskedEmail || curUrl.includes('login.live.com')))) {
|
|
365
|
-
if (!passwordFilled) {
|
|
366
|
-
// 再次扫描页面是否存在“使用密码”入口
|
|
367
|
-
const canSwitch = await this.tryClickUsePassword(cdp);
|
|
368
|
-
if (canSwitch && usePasswordAttempts < 6) {
|
|
369
|
-
usePasswordAttempts++;
|
|
370
|
-
securityProofDetectedCount = 0;
|
|
371
|
-
await new Promise((r) => setTimeout(r, 1500));
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
// 给予 3 次缓冲探测机会(约 3 秒),等待前端页面渲染出“使用密码”
|
|
375
|
-
securityProofDetectedCount++;
|
|
376
|
-
if (securityProofDetectedCount < 3) {
|
|
377
|
-
await new Promise((r) => setTimeout(r, 1000));
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
// 确认实在没有密码登录方式,或者是密码提交后强制要求的辅助邮箱验证码,才真正停下交接
|
|
382
|
-
await cdp.bringToFront();
|
|
383
|
-
cdp.disconnect();
|
|
384
|
-
return {
|
|
385
|
-
success: true,
|
|
386
|
-
email,
|
|
387
|
-
status: 'manual_required',
|
|
388
|
-
profileDir,
|
|
389
|
-
message: '微软要求安全验证 (辅助邮箱验证码/两步验证/补充信息),当前页面无可用密码通道,已为您置顶浏览器窗口,请手动完成验证。',
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
376
|
// 状态 8: 官网营销页误跳转处理
|
|
393
377
|
if (curUrl.includes('microsoft.com') && curUrl.includes('outlook')) {
|
|
394
378
|
const clicked = await cdp.click("a[href*='login.live.com'], a[href*='outlook.live.com']");
|
|
@@ -429,13 +413,11 @@ export class OutlookLauncher {
|
|
|
429
413
|
*/
|
|
430
414
|
static async tryClickUsePassword(cdp) {
|
|
431
415
|
try {
|
|
432
|
-
const
|
|
433
|
-
// 1.
|
|
416
|
+
const res = await cdp.evaluate(`(() => {
|
|
417
|
+
// 1. 若存在半透明全屏加载蒙层,穿透它
|
|
434
418
|
const loaders = document.querySelectorAll('div[aria-label*="加载"], div[aria-label*="loading"]');
|
|
435
419
|
loaders.forEach(l => {
|
|
436
|
-
if (l instanceof HTMLElement)
|
|
437
|
-
l.style.pointerEvents = 'none';
|
|
438
|
-
}
|
|
420
|
+
if (l instanceof HTMLElement) l.style.pointerEvents = 'none';
|
|
439
421
|
});
|
|
440
422
|
|
|
441
423
|
const isVisible = (el) => {
|
|
@@ -445,110 +427,114 @@ export class OutlookLauncher {
|
|
|
445
427
|
return rect.width > 0 && rect.height > 0 && style.visibility !== 'hidden' && style.display !== 'none';
|
|
446
428
|
};
|
|
447
429
|
|
|
448
|
-
|
|
449
|
-
|
|
430
|
+
const doClick = (el) => {
|
|
431
|
+
try {
|
|
432
|
+
el.scrollIntoView({ block: 'center' });
|
|
433
|
+
el.focus();
|
|
434
|
+
el.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true, view: window }));
|
|
435
|
+
el.dispatchEvent(new MouseEvent('mouseup', { bubbles: true, cancelable: true, view: window }));
|
|
436
|
+
el.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
|
|
437
|
+
if (typeof el.click === 'function') el.click();
|
|
438
|
+
} catch {}
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
// 优先级 1: 查找显式“使用密码 / 密码登录”入口 (官方专有 ID 以及包含密码/password 的凭据瓷贴与按钮)
|
|
442
|
+
const pwdSelectors = [
|
|
450
443
|
'#idA_PWD_SwitchToPassword',
|
|
451
444
|
'#idA_IL_SwitchToPassword',
|
|
452
|
-
'#signInAnotherWay',
|
|
453
|
-
'#idA_PWD_SwitchToCredPicker',
|
|
454
445
|
'a[role="button"][id*="SwitchToPassword"]',
|
|
455
446
|
'button[id*="SwitchToPassword"]',
|
|
456
447
|
'a[id*="SwitchToPassword"]',
|
|
457
448
|
'a[id*="switchToPassword"]',
|
|
458
|
-
'
|
|
459
|
-
'
|
|
460
|
-
'button.fui-Link',
|
|
461
|
-
'a.fui-Link',
|
|
449
|
+
'#credentialList [role="button"]',
|
|
450
|
+
'.tile',
|
|
462
451
|
];
|
|
463
452
|
|
|
464
|
-
for (const sel of
|
|
453
|
+
for (const sel of pwdSelectors) {
|
|
465
454
|
const matches = Array.from(document.querySelectorAll(sel));
|
|
466
455
|
for (const el of matches) {
|
|
467
456
|
if (isVisible(el)) {
|
|
468
|
-
const text = (el.innerText || el.textContent || '').trim().toLowerCase();
|
|
469
|
-
if (
|
|
470
|
-
el
|
|
457
|
+
const text = (el.innerText || el.textContent || el.getAttribute('aria-label') || '').trim().toLowerCase();
|
|
458
|
+
if (text.includes('密码') || text.includes('password') || sel.includes('Password')) {
|
|
459
|
+
doClick(el);
|
|
471
460
|
const r = el.getBoundingClientRect();
|
|
472
|
-
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
|
|
461
|
+
return { point: { x: r.left + r.width / 2, y: r.top + r.height / 2 }, type: 'password' };
|
|
473
462
|
}
|
|
474
463
|
}
|
|
475
464
|
}
|
|
476
465
|
}
|
|
477
466
|
|
|
478
|
-
//
|
|
479
|
-
const
|
|
467
|
+
// 优先级 1.5: 页面内包含“密码”的各类交互链接 (a, button, span.fui-Link 等)
|
|
468
|
+
const pwdMarkers = [
|
|
480
469
|
'使用密码',
|
|
481
470
|
'改用密码',
|
|
482
471
|
'密码登录',
|
|
483
472
|
'输入你的密码',
|
|
473
|
+
'输入密码',
|
|
484
474
|
'使用你的密码',
|
|
485
|
-
'使用另一种方式登录',
|
|
486
|
-
'使用其他方式登录',
|
|
487
|
-
'其他登录方式',
|
|
488
|
-
'通过其他方式登录',
|
|
489
475
|
'use your password',
|
|
490
476
|
'use password',
|
|
491
477
|
'use your password instead',
|
|
492
478
|
'sign in with password',
|
|
493
479
|
'sign in with your password',
|
|
494
|
-
'sign in another way',
|
|
495
|
-
'other ways to sign in',
|
|
496
480
|
];
|
|
497
481
|
|
|
498
482
|
const interactiveNodes = Array.from(document.querySelectorAll('[role="button"], button, a, span.fui-Link, div[role="button"]'));
|
|
499
483
|
for (const el of interactiveNodes) {
|
|
500
484
|
if (!isVisible(el)) continue;
|
|
501
485
|
const text = (el.innerText || el.textContent || el.getAttribute('aria-label') || '').trim().replace(/\\s+/g, ' ').toLowerCase();
|
|
502
|
-
for (const m of
|
|
486
|
+
for (const m of pwdMarkers) {
|
|
503
487
|
if (text === m || (text.includes(m) && text.length <= m.length + 10)) {
|
|
504
|
-
el
|
|
488
|
+
doClick(el);
|
|
505
489
|
const r = el.getBoundingClientRect();
|
|
506
|
-
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
|
|
490
|
+
return { point: { x: r.left + r.width / 2, y: r.top + r.height / 2 }, type: 'password' };
|
|
507
491
|
}
|
|
508
492
|
}
|
|
509
493
|
}
|
|
510
494
|
|
|
511
|
-
//
|
|
512
|
-
const
|
|
513
|
-
for (const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (text === m || (text.includes(m) && text.length <= m.length + 8)) {
|
|
520
|
-
const innerAction = node.querySelector('[role="button"], a, button, .fui-Link');
|
|
521
|
-
const target = innerAction || node.closest('[role="button"], button, a, [tabindex]') || node;
|
|
522
|
-
target.scrollIntoView({ block: 'center' });
|
|
523
|
-
const r = target.getBoundingClientRect();
|
|
524
|
-
return { x: r.left + r.width / 2, y: r.top + r.height / 2 };
|
|
525
|
-
}
|
|
495
|
+
// 优先级 2: 若未找到直接的密码入口,点击“其他登录方式 / Sign in another way”展开凭据选择列表
|
|
496
|
+
const anotherWaySelectors = ['#signInAnotherWay', '#idA_PWD_SwitchToCredPicker'];
|
|
497
|
+
for (const sel of anotherWaySelectors) {
|
|
498
|
+
const el = document.querySelector(sel);
|
|
499
|
+
if (isVisible(el)) {
|
|
500
|
+
doClick(el);
|
|
501
|
+
const r = el.getBoundingClientRect();
|
|
502
|
+
return { point: { x: r.left + r.width / 2, y: r.top + r.height / 2 }, type: 'another_way' };
|
|
526
503
|
}
|
|
527
504
|
}
|
|
528
505
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
506
|
+
const anotherMarkers = [
|
|
507
|
+
'使用另一种方式登录',
|
|
508
|
+
'使用其他方式登录',
|
|
509
|
+
'其他登录方式',
|
|
510
|
+
'其他方式',
|
|
511
|
+
'通过其他方式登录',
|
|
512
|
+
'sign in another way',
|
|
513
|
+
'other ways to sign in',
|
|
514
|
+
];
|
|
515
|
+
for (const el of interactiveNodes) {
|
|
516
|
+
if (!isVisible(el)) continue;
|
|
517
|
+
const text = (el.innerText || el.textContent || el.getAttribute('aria-label') || '').trim().replace(/\\s+/g, ' ').toLowerCase();
|
|
518
|
+
for (const m of anotherMarkers) {
|
|
519
|
+
if (text === m || (text.includes(m) && text.length <= m.length + 10)) {
|
|
520
|
+
doClick(el);
|
|
521
|
+
const r = el.getBoundingClientRect();
|
|
522
|
+
return { point: { x: r.left + r.width / 2, y: r.top + r.height / 2 }, type: 'another_way' };
|
|
523
|
+
}
|
|
538
524
|
}
|
|
539
525
|
}
|
|
540
526
|
|
|
541
527
|
return null;
|
|
542
528
|
})()`);
|
|
543
|
-
if (
|
|
544
|
-
//
|
|
545
|
-
await cdp.clickPoint(point.x, point.y);
|
|
546
|
-
return true;
|
|
529
|
+
if (res && res.point) {
|
|
530
|
+
// 同步派发真实 CDP 鼠标物理点击
|
|
531
|
+
await cdp.clickPoint(res.point.x, res.point.y);
|
|
532
|
+
return { clicked: true, type: res.type };
|
|
547
533
|
}
|
|
548
|
-
return false;
|
|
534
|
+
return { clicked: false };
|
|
549
535
|
}
|
|
550
536
|
catch {
|
|
551
|
-
return false;
|
|
537
|
+
return { clicked: false };
|
|
552
538
|
}
|
|
553
539
|
}
|
|
554
540
|
/**
|
|
@@ -613,48 +599,90 @@ export class OutlookLauncher {
|
|
|
613
599
|
}
|
|
614
600
|
/**
|
|
615
601
|
* 在已到达 Outlook 收件箱页面时,利用 CDP 实时嗅探 Cursor / WorkOS 最新的 6 位数字验证码
|
|
602
|
+
* 增强特性:
|
|
603
|
+
* 1. 自动识别并无感切换【重点 / 其他 (Other)】选项卡,彻底击破微软邮件分类盲区
|
|
604
|
+
* 2. 毫秒级匹配邮件列表项预览摘要 (如 "Your one-time code is 298372"),无需等待正文复杂渲染
|
|
605
|
+
* 3. 兼容卡片大字号、iframe 嵌套及多语系正则提取,捕获即完成
|
|
616
606
|
*/
|
|
617
|
-
static async sniffVerificationCode(cdp, timeoutMs =
|
|
607
|
+
static async sniffVerificationCode(cdp, timeoutMs = 35000) {
|
|
618
608
|
const end = Date.now() + timeoutMs;
|
|
619
|
-
console.log(chalk.cyan(' →
|
|
620
|
-
|
|
621
|
-
|
|
609
|
+
console.log(chalk.cyan(' → 浏览器已成功进入收件箱,正在全自动嗅探提取 6 位验证码...'));
|
|
610
|
+
let attempt = 0;
|
|
611
|
+
let hasSwitchedToOther = false;
|
|
612
|
+
// 初始等待 1.2 秒让 Outlook 单页应用渲染出邮件主框架
|
|
613
|
+
await new Promise((r) => setTimeout(r, 1200));
|
|
622
614
|
while (Date.now() < end) {
|
|
615
|
+
attempt++;
|
|
623
616
|
try {
|
|
617
|
+
// 关键逻辑:若在当前栏扫描 2 次未果,主动检测并点击【其他】(Other) 分类选项卡!
|
|
618
|
+
if (attempt >= 2 && !hasSwitchedToOther) {
|
|
619
|
+
const switched = await cdp.evaluate(`(() => {
|
|
620
|
+
const tabs = Array.from(document.querySelectorAll('button, div[role="tab"], span[role="tab"], a, [aria-label*="其他"], [aria-label*="Other"]'));
|
|
621
|
+
for (const t of tabs) {
|
|
622
|
+
const text = ((t.innerText || t.textContent || t.getAttribute('aria-label') || '').trim());
|
|
623
|
+
if (text === '其他' || text === 'Other' || text.startsWith('其他') || text.startsWith('Other')) {
|
|
624
|
+
const isSelected = t.getAttribute('aria-selected') === 'true' || t.classList.contains('is-selected') || t.classList.contains('active');
|
|
625
|
+
if (!isSelected) {
|
|
626
|
+
(t as HTMLElement).click();
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return false;
|
|
632
|
+
})()`);
|
|
633
|
+
if (switched) {
|
|
634
|
+
hasSwitchedToOther = true;
|
|
635
|
+
console.log(chalk.grey(' → 正在自动巡检【其他 / Other】邮件分类栏...'));
|
|
636
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
637
|
+
}
|
|
638
|
+
}
|
|
624
639
|
const found = await cdp.evaluate(`(() => {
|
|
625
|
-
// 1.
|
|
626
|
-
const
|
|
627
|
-
|
|
640
|
+
// 1. 全文/阅读窗格直接正则提取 (包括列表摘要及展开后的卡片正文)
|
|
641
|
+
const fullText = (document.body ? (document.body.innerText + '\\n' + document.body.textContent) : '');
|
|
642
|
+
|
|
643
|
+
// 1.1 精准匹配 Cursor 官方模板规则 (例如: "Your one-time code is 298372" / "Your code is 298372")
|
|
644
|
+
const directMatch = fullText.match(/(?:one-time code is|code is|your code is|one-time code|验证码为|验证码是|验证代码为|验证代码是)[^\\d]{0,25}(\\d{6})\\b/i);
|
|
645
|
+
if (directMatch && directMatch[1]) {
|
|
646
|
+
return directMatch[1];
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
// 2. 检查邮件列表项 (左侧邮件列表)
|
|
650
|
+
const mailItems = Array.from(document.querySelectorAll('div[role="option"], div[data-convid], div[aria-label*="Cursor"], div[aria-label*="cursor"], div[draggable="true"]'));
|
|
651
|
+
for (const item of mailItems) {
|
|
628
652
|
const label = ((item.getAttribute('aria-label') || '') + ' ' + (item.innerText || '')).trim();
|
|
629
|
-
if (/cursor|workos/i.test(label)) {
|
|
630
|
-
//
|
|
631
|
-
const m = label.match(
|
|
632
|
-
if (m
|
|
633
|
-
|
|
653
|
+
if (/cursor|workos|sign in to cursor/i.test(label)) {
|
|
654
|
+
// 邮件列表项的摘要预览文本中通常直接包含: "Your one-time code is 298372. Th..."
|
|
655
|
+
const m = label.match(/(?:one-time code is|code is|code\\s*|验证码[::\\s]*|\\b)(\\d{6})\\b/i);
|
|
656
|
+
if (m && m[1]) {
|
|
657
|
+
return m[1];
|
|
658
|
+
}
|
|
659
|
+
// 尝试点选该邮件项展开阅读窗格
|
|
634
660
|
try { (item as HTMLElement).click(); } catch {}
|
|
635
|
-
break;
|
|
636
661
|
}
|
|
637
662
|
}
|
|
638
663
|
|
|
639
|
-
//
|
|
640
|
-
const
|
|
641
|
-
const
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const readingPane = document.querySelector('div[role="region"][aria-label*="Reading"], div[data-app-section="ConversationReadingPane"], div[aria-label*="邮件内容"], #Item\\.MessageUniqueBody');
|
|
648
|
-
if (readingPane) {
|
|
649
|
-
const m = (readingPane as HTMLElement).innerText.match(/\\b(\\d{6})\\b/);
|
|
650
|
-
if (m) return m[1];
|
|
664
|
+
// 3. 检查右侧阅读窗格或大号突出数字 (卡片大字号)
|
|
665
|
+
const readingPanes = Array.from(document.querySelectorAll('div[role="region"], div[data-app-section="ConversationReadingPane"], div[aria-label*="邮件内容"], div[aria-label*="Reading"], #Item\\\\.MessageUniqueBody, div[aria-label*="Cursor"]'));
|
|
666
|
+
for (const rp of readingPanes) {
|
|
667
|
+
const text = (rp as HTMLElement).innerText || '';
|
|
668
|
+
if (/cursor|one-time code|sign in/i.test(text)) {
|
|
669
|
+
const m = text.match(/(?:code is|one-time code|验证码)[^\\d]{0,40}(\\d{6})\\b/i) || text.match(/\\b(\\d{6})\\b/);
|
|
670
|
+
if (m && m[1]) return m[1];
|
|
671
|
+
}
|
|
651
672
|
}
|
|
652
673
|
|
|
653
|
-
// 4.
|
|
654
|
-
const
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
674
|
+
// 4. 检查可能嵌套在 iframe 里的邮件正文 (部分 Outlook 版本的正文置于隔离 iframe)
|
|
675
|
+
const iframes = Array.from(document.querySelectorAll('iframe'));
|
|
676
|
+
for (const f of iframes) {
|
|
677
|
+
try {
|
|
678
|
+
const doc = f.contentDocument || f.contentWindow?.document;
|
|
679
|
+
if (doc && doc.body) {
|
|
680
|
+
const iText = doc.body.innerText || doc.body.textContent || '';
|
|
681
|
+
const m = iText.match(/(?:one-time code is|code is|one-time code|验证码)[^\\d]{0,25}(\\d{6})\\b/i) ||
|
|
682
|
+
(iText.includes('Cursor') ? iText.match(/\\b(\\d{6})\\b/) : null);
|
|
683
|
+
if (m && m[1]) return m[1];
|
|
684
|
+
}
|
|
685
|
+
} catch {}
|
|
658
686
|
}
|
|
659
687
|
|
|
660
688
|
return null;
|
|
@@ -664,7 +692,7 @@ export class OutlookLauncher {
|
|
|
664
692
|
}
|
|
665
693
|
}
|
|
666
694
|
catch { }
|
|
667
|
-
await new Promise((r) => setTimeout(r,
|
|
695
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
668
696
|
}
|
|
669
697
|
return null;
|
|
670
698
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { AccountStore } from './account-store.js';
|
|
7
7
|
import { StorageBridge } from './storage-bridge.js';
|
|
8
8
|
import { SqliteBridge } from './sqlite-bridge.js';
|
|
9
|
+
import type { AccountInfo } from '../types.js';
|
|
9
10
|
export interface ParsedAccount {
|
|
10
11
|
email: string;
|
|
11
12
|
emailPassword: string;
|
|
@@ -58,11 +59,30 @@ export declare class PureLoginService {
|
|
|
58
59
|
phoneMask?: string;
|
|
59
60
|
}>;
|
|
60
61
|
/**
|
|
61
|
-
*
|
|
62
|
+
* 向云端申请重新发送验证码 (同会话重发,不扣减卡密额度)
|
|
63
|
+
*/
|
|
64
|
+
resendCode(taskId: string, cardCode: string, email: string): Promise<{
|
|
65
|
+
ok: boolean;
|
|
66
|
+
message: string;
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* 结构化查询云端邮箱验证码并精准解析是否可重试
|
|
70
|
+
*/
|
|
71
|
+
fetchMailCodeResult(email: string, emailPassword: string, cursorPassword?: string): Promise<{
|
|
72
|
+
ok: boolean;
|
|
73
|
+
code?: string;
|
|
74
|
+
retryable: boolean;
|
|
75
|
+
message: string;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* 自动从用户邮箱中提取最新 6 位数字验证码 (保留兼容性)
|
|
62
79
|
*/
|
|
63
80
|
autoFetchMailCode(email: string, emailPassword: string, cursorPassword?: string): Promise<string | null>;
|
|
64
81
|
/**
|
|
65
82
|
* 交互式运行纯净代登全流程 (终端交互式 TUI)
|
|
66
83
|
*/
|
|
67
|
-
runInteractiveFlow(store: AccountStore, storage: StorageBridge, sqlite: SqliteBridge, executablePath?: string
|
|
84
|
+
runInteractiveFlow(store: AccountStore, storage: StorageBridge, sqlite: SqliteBridge, executablePath?: string, options?: {
|
|
85
|
+
prefilledInput?: string;
|
|
86
|
+
skipSwitchPrompt?: boolean;
|
|
87
|
+
}): Promise<AccountInfo | null>;
|
|
68
88
|
}
|