Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangsx committed Sep 4, 2024
1 parent f943d72 commit b5209fa
Showing 1 changed file with 1 addition and 127 deletions.
128 changes: 1 addition & 127 deletions utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,133 +405,7 @@ export async function loginGoogleNew(page: Page, opt: GoogleMailAccount) {
}

export async function googleScreenHandle(page: Page, opt: GoogleMailAccount) {
const url = await page.evaluate(() => window.location.href);
if (!url.includes('accounts.google.com')) {
console.log(`no login page, login ok! Now at ${url}`);
return true;
}
const pathname = new URL(url).pathname;
const title = await page.evaluate(
() => document.querySelector('#headingText')?.textContent,
);
console.log(`screen at: ${pathname} ${title}`);
switch (pathname) {
case '/v3/signin/identifier':
await page.click('#identifierId');
await page.keyboard.type(opt.email, { delay: 10 });
await sleep(1000);
await page.waitForSelector('#identifierNext > div > button > span');
await page.click('#identifierNext > div > button > span');
break;
case '/v3/signin/challenge/recaptcha':
await sleep(20 * 1000);
await page.waitForSelector('button');
await page.click('button');
break;
case '/v3/signin/challenge/pwd':
await page.waitForSelector('input[type="password"]', { visible: true });
await sleep(1000);
await page.click('input[type="password"]', { delay: 50 });
await sleep(1000);
await page.keyboard.type(opt.password, { delay: 10 });
await page.waitForSelector('#passwordNext > div > button > span');
await page.click('#passwordNext > div > button > span');
break;
case '/v3/signin/challenge/ipp/consent': // 短信验证界面 选择是 text 还是 call
const btn = await page.evaluate(() =>
Array.from(document.querySelectorAll('button')).map(
(v) => v.textContent,
),
);
console.log(`got buttons: ${btn.join('|')}`);
await page.waitForSelector('button');
await page.click('button');
break;
case '/v3/signin/challenge/selection': // 选择界面 选短信验证
const actions = await page.evaluate(() =>
Array.from(document.querySelector('form')!.querySelectorAll('li')).map(
(v) => v.textContent,
),
);
if (!actions?.length) {
break;
}
console.log(`title:[${title}] got actions |${actions.join('|')}|`);
if (actions.includes('Confirm your recovery email')) {
// recovery email验证
if (!opt.recovery) {
throw new Error('need recovery email');
}
await page.waitForSelector('li:nth-child(3)');
await page.click('li:nth-child(3)');
await sleep(2000);
await page.waitForSelector('input');
await page.click('input');
await page.keyboard.type(opt.recovery);
await page.keyboard.press('Enter');
break;
}
if (actions.find((v) => v?.includes('Get a verification code at'))) {
// 选择短信验证
await page.waitForSelector('li:nth-child(1)');
await page.click('li:nth-child(1)');
break;
}
if (title === 'Use a phone number from your account') {
await page.waitForSelector(`div[data-challengevariant="SMS"]`);
await page.click(`div[data-challengevariant="SMS"]`);
break;
}
throw new Error('unknown action');
case '/v3/signin/challenge/ipp/verify':
await page.waitForSelector('input[type="tel"]');
await page.click('input[type="tel"]');
if (!opt.sms_url) {
throw new Error('need sms_url');
}
await sleep(5000);
const code = await retryFunc(async () => GetSMSFromAPI(opt.sms_url!), 3, {
defaultV: null,
});
if (!code) {
console.log('no code');
break;
}
await page.keyboard.type(code, { delay: 10 });
await page.keyboard.press('Enter');
break;
case '/v3/signin/challenge/kpp':
if (!opt.phone) {
throw new Error('need phone');
}
await page.waitForSelector('#phoneNumberId');
await page.click('#phoneNumberId');
await page.keyboard.type(opt.phone, { delay: 10 });
await page.keyboard.press('Enter');
break;
case '/accounts/SetSID':
await sleep(3000);
break;
case '/signin/oauth/id': //是否同意授权界面
await page.waitForSelector(
'c-wiz > div > div > div > div > div:nth-child(2)',
);
await sleep(1000);
await page.click('c-wiz > div > div > div > div > div:nth-child(2)');
break;
case '/v3/signin/rejected':
throw new Error('account fk banned');
case '/signin/v2/disabled/explanation':
throw new Error('account fk banned');
case '/speedbump/gaplustos':
await page.waitForSelector('#confirm', {});
await sleep(1000);
await page.click('#confirm');
break;
default:
throw new Error(`unknown pathname: ${pathname}`);
}
return false;
return true;
}

export async function GetSMSFromAPI(url: string) {
Expand Down

0 comments on commit b5209fa

Please sign in to comment.