From 828e9871192456b29b9632220b693b2ad0b8567c Mon Sep 17 00:00:00 2001 From: yema <1304119519@qq.com> Date: Mon, 5 Jun 2023 20:13:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20google=20=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=B8=AD=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/main/gpt/login.ts | 2 +- electron/main/poe/getLink.js | 52 ------- electron/main/poe/getLink.ts | 74 +++++++++ electron/main/poe/{login.js => login.ts} | 34 ++++- electron/main/tools.js | 5 - electron/main/tools.ts | 12 ++ src/App.vue | 183 ++++++++++++----------- 7 files changed, 205 insertions(+), 157 deletions(-) delete mode 100644 electron/main/poe/getLink.js create mode 100644 electron/main/poe/getLink.ts rename electron/main/poe/{login.js => login.ts} (69%) delete mode 100644 electron/main/tools.js create mode 100644 electron/main/tools.ts diff --git a/electron/main/gpt/login.ts b/electron/main/gpt/login.ts index facbbe3..77ac81c 100644 --- a/electron/main/gpt/login.ts +++ b/electron/main/gpt/login.ts @@ -38,7 +38,7 @@ export async function login(options, tryCount = 1): Promise { // log('准备进入 google 登录页') const [response] = await Promise.all([ - page.waitForNavigation(() => location.href.startsWith('https://auth0.openai.com/u/login/identifier')), + page.waitForNavigation({ timeout: 10000 }), page.click('button') ]) // log('已进入 google 登录页') diff --git a/electron/main/poe/getLink.js b/electron/main/poe/getLink.js deleted file mode 100644 index 37d7201..0000000 --- a/electron/main/poe/getLink.js +++ /dev/null @@ -1,52 +0,0 @@ -import { clog, loginGoogle } from './login' -import { readFileSync, writeFileSync } from 'fs' -import path from 'path' -import { EOL } from 'os' - -export async function getLink(options) { - const log = clog(options) - log('开始', { ident: 'poe-link' }) - const page = await loginGoogle(options) - - await Promise.all([ - page.waitForNavigation(), - page.goto('https://poe.com/settings') - ]) - - log('已进入设置页面, 检查中') - - // page.waitForTimeout(1000) - await page.waitForSelector('[class*=SettingsSubscriptionSection_subscribeButton]') - log('1, 开始点击显示订阅套餐按钮') - await page.click('[class*=SettingsSubscriptionSection_subscribeButton]') - log('2, 开始点击显示更多套餐') - await page.waitForSelector('[class*=WebSubscriptionFreeTrial_viewAllPlansButton]') - await page.click('[class*=WebSubscriptionFreeTrial_viewAllPlansButton]') - log('3, 开始点击最后一个套餐') - await page.waitForSelector('[class*=WebSubscriptionPaywall_plans]') - await page.click('[class*=WebSubscriptionPaywall_plans] > button:last-child') - - // 点击订阅 - log('4, 开始点击订阅') - page.click('[class*=WebSubscriptionPaywall_button]') - const [response] = await Promise.all([ - page.waitForNavigation({ waitUntil: 'domcontentloaded' }), - ]) - - if (response.ok()) { - const url = response._request._frame._url - log('获取链接成功', { result: url, type: 'success' }) - return url - - // if (options.index === 0) { - // writeFileSync(resolve('./hao.txt'), '', 'utf8') - // } - // const fileContent = readFileSync(resolve('./hao.txt'), 'utf8') - // writeFileSync(resolve('./hao.txt'), fileContent + `${EOL}${options.index + 1} ${options.user}${EOL}${url}`, 'utf8') - } -} - - -function resolve(url) { - return path.resolve(__dirname, '../src/poe/', url) -} diff --git a/electron/main/poe/getLink.ts b/electron/main/poe/getLink.ts new file mode 100644 index 0000000..919eb0d --- /dev/null +++ b/electron/main/poe/getLink.ts @@ -0,0 +1,74 @@ +import { clog, loginGoogle } from './login' +import type { Browser, Page } from 'puppeteer' +import { readFileSync, writeFileSync } from 'fs' +import path from 'path' +import { EOL } from 'os' + +function existDialog(page: Page) { + return page.evaluate((selector, searchText) => { + const elements = Array.from(document.querySelectorAll(selector)); + const target = elements.find(el => el.textContent.trim() === searchText); + target && target.click() + + return !!target + }, 'button', 'Start free trial') +} + +export async function getLink(options) { + const log = clog(options) + log('开始', { ident: 'poe-link' }) + return loginGoogle(options).then(async (page: Page) => { + await page.waitForTimeout(1000) + const isExistDialog = await existDialog(page) + + isExistDialog && log('检测到充值弹窗,无需前往设置页') + + if (!isExistDialog) { + await Promise.all([ + page.waitForNavigation(), + page.goto('https://poe.com/settings') + ]) + log('已进入设置页面, 检查中') + await page.waitForSelector('[class*=SettingsSubscriptionSection_subscribeButton]') + log('点击显示订阅套餐按钮') + await page.click('[class*=SettingsSubscriptionSection_subscribeButton]') + } + + log('显示更多套餐') + await page.waitForSelector('[class*=WebSubscriptionFreeTrial_viewAllPlansButton]') + await page.click('[class*=WebSubscriptionFreeTrial_viewAllPlansButton]') + log('点击最后一个套餐') + await page.waitForSelector('[class*=WebSubscriptionPaywall_plans]') + await page.click('[class*=WebSubscriptionPaywall_plans] > button:last-child') + + // 点击订阅 + log('4, 开始点击订阅') + page.click('[class*=WebSubscriptionPaywall_button]') + const [response] = await Promise.all([ + page.waitForNavigation({ waitUntil: 'domcontentloaded' }), + ]) + + if (response.ok()) { + const url = response._request._frame._url + log('获取链接成功', { result: url, type: 'success' }) + return url + + // if (options.index === 0) { + // writeFileSync(resolve('./hao.txt'), '', 'utf8') + // } + // const fileContent = readFileSync(resolve('./hao.txt'), 'utf8') + // writeFileSync(resolve('./hao.txt'), fileContent + `${EOL}${options.index + 1} ${options.user}${EOL}${url}`, 'utf8') + } + }).catch(error => { + console.log('error ->', error.try, error.text, error) + if (error?.try) { + return getLink(options) + } + }) + +} + + +function resolve(url) { + return path.resolve(__dirname, '../src/poe/', url) +} diff --git a/electron/main/poe/login.js b/electron/main/poe/login.ts similarity index 69% rename from electron/main/poe/login.js rename to electron/main/poe/login.ts index 7693990..da8502b 100644 --- a/electron/main/poe/login.js +++ b/electron/main/poe/login.ts @@ -1,13 +1,13 @@ +import type { Browser, Page } from 'puppeteer' import puppeteer from 'puppeteer-extra' import StealthPlugin from 'puppeteer-extra-plugin-stealth' -import { randomNum } from '../tools' +import { randomNum, awaitWrap } from '../tools' import { win } from '../index' puppeteer.use(StealthPlugin()) - let id -export let browser +export let browser: Browser /** * 登录google */ @@ -38,10 +38,13 @@ export async function loginGoogle(options, tryCount = 1) { await page.waitForTimeout(randomNum(1000, 2600)) log('准备进入 google 登录页') - const [response] = await Promise.all([ - page.waitForNavigation(() => location.href.startsWith('https://accounts.google.com')), - page.click('.ContinueWithGoogleButton_buttonContentWrapper__Mrp0W') - ]) + + page.click('.ContinueWithGoogleButton_buttonContentWrapper__Mrp0W') + const [err, response] = await awaitWrap(page.waitForNavigation({ timeout: 10000 })) + if (err) { + reject({ text: '登录报错', try: true }) + return p + } log('已进入 google 登录页') if (response.ok()) { @@ -53,6 +56,11 @@ export async function loginGoogle(options, tryCount = 1) { await page.keyboard.press('Enter') ]) log('已输入账号,准备输入密码') + if (await isError(page)) { + reject({ text: '登录报错', try: true }) + return p + } + await page.waitForSelector('input[type="password"]', { visible: true }) await page.type('input[type="password"]', env.GPASS) log('已输入密码,开始登录') @@ -60,6 +68,10 @@ export async function loginGoogle(options, tryCount = 1) { page.waitForFunction(() => location.href === 'https://poe.com/'), await page.keyboard.press('Enter') ]) + if (await isError(page)) { + reject({ text: '登录报错', try: true }) + return p + } log('登录成功,准备进入 poe') @@ -79,11 +91,17 @@ export async function loginGoogle(options, tryCount = 1) { // return Promise.reject('google 登录失败') } +async function isError(page: Page) { + const text = await page.evaluate(() => (document.querySelector('p')?.textContent || '')); + // const text = await page.evaluate('p', element => element.textContent); + return text && text.includes('error') +} + export function clog(options) { return (info, data = {}) => { if (win) { - win.webContents.send('progress', {...options, info, ...data}) + win.webContents.send('progress', { ...options, info, ...data }) } } } diff --git a/electron/main/tools.js b/electron/main/tools.js deleted file mode 100644 index 10ddf5c..0000000 --- a/electron/main/tools.js +++ /dev/null @@ -1,5 +0,0 @@ - -//生成从minNum到maxNum的随机数 -export function randomNum (min, max) { - return parseInt(Math.random() * (max - min + 1) + min) -} diff --git a/electron/main/tools.ts b/electron/main/tools.ts new file mode 100644 index 0000000..7f2b5bd --- /dev/null +++ b/electron/main/tools.ts @@ -0,0 +1,12 @@ + +//生成从minNum到maxNum的随机数 +export function randomNum (min, max) { + return parseInt(Math.random() * (max - min + 1) + min) +} + +// promise 错误处理 +export function awaitWrap(promise: Promise): Promise<[U | null, T | null]> { + return promise + .then<[null, T]>((data: T) => [null, data]) + .catch<[U, null]>(err => [err, null]) +} diff --git a/src/App.vue b/src/App.vue index 88a45ff..d9eb807 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,99 +2,100 @@ import { ipcRenderer } from 'electron' import { NButton } from 'naive-ui' import { useClipboard } from '@vueuse/core' -const input = ref('upperside79@mail.com----Hellowpo!') +const input = ref('126vdsjmgyanpgqrvb@ddmvp.icu----EOJ2NgPfS') +// const input = ref('traceetakashi6274@gmail.com----kedaraditi0214----kedaraditi4760@hotmail.com') const result = ref('') const list = ref([ - { - "user": "jannettamoses5977@gmail.com", - "pass": "kenyatearle7610", - "auxiliary": "kenyatearle8223@outlook.com", - "index": 0, - "id": "jannettamoses5977@gmail.com", - "info": "成功😘", - "ident": "poe-link", - "type": "success", - "result": "成功😘" - }, - { - "user": "tylanindea7687@gmail.com", - "pass": "adalbertokanisha4845", - "auxiliary": "adalbertokanisha8803@yandex.com", - "index": 1, - "id": "tylanindea7687@gmail.com", - "info": "成功😘", - "ident": "poe-validate", - "type": "success", - "result": "成功😘" - }, - { - "user": "bayanjae8652@gmail.com", - "pass": "lorenarosamond4075", - "auxiliary": "lorenarosamond8958@outlook.com", - "index": 2, - "id": "bayanjae8652@gmail.com", - "info": "成功😘", - "ident": "poe-validate", - "type": "fail", - "result": "成功😘" - }, - { - "user": "geneviashametra1019@gmail.com", - "pass": "sheypervis2156", - "auxiliary": "sheypervis0163@qq.com", - "index": 3, - "id": "geneviashametra1019@gmail.com", - "info": "成功😘", - "ident": "poe-validate", - "type": "success", - "result": "成功😘" - }, - { - "user": "marikamelindasue5911@gmail.com", - "pass": "ambrbreeann4103", - "auxiliary": "ambrbreeann5643@icloud.com", - "index": 4, - "id": "marikamelindasue5911@gmail.com", - "info": "成功😘", - "ident": "poe-validate", - "type": "success", - "result": "成功😘" - }, - { - "user": "caterinereba2981@gmail.com", - "pass": "arvisleo0563", - "auxiliary": "arvisleo1265@zoho.com", - "index": 5, - "id": "caterinereba2981@gmail.com", - "info": "成功😘", - "ident": "poe-validate", - "type": "success", - "result": "成功😘" - }, - { - "user": "adairaderrell9992@gmail.com", - "pass": "adairaderrell8698", - "auxiliary": "adairaderrell1859@hotmail.com", - "index": 6, - "id": "adairaderrell9992@gmail.com", - "info": "成功😘", - "ident": "poe-validate", - "type": "success", - "result": "成功😘" - }, - { - "user": "nishadarrow0444@gmail.com", - "pass": "cliftontiffani7462", - "auxiliary": "cliftontiffani2263@hotmail.com", - "index": 7, - "id": "nishadarrow0444@gmail.com", - "info": "成功😘", - "ident": "poe-validate", - "type": "success", - "result": "成功😘" - } + // { + // "user": "jannettamoses5977@gmail.com", + // "pass": "kenyatearle7610", + // "auxiliary": "kenyatearle8223@outlook.com", + // "index": 0, + // "id": "jannettamoses5977@gmail.com", + // "info": "成功😘", + // "ident": "poe-link", + // "type": "success", + // "result": "成功😘" + // }, + // { + // "user": "tylanindea7687@gmail.com", + // "pass": "adalbertokanisha4845", + // "auxiliary": "adalbertokanisha8803@yandex.com", + // "index": 1, + // "id": "tylanindea7687@gmail.com", + // "info": "成功😘", + // "ident": "poe-validate", + // "type": "success", + // "result": "成功😘" + // }, + // { + // "user": "bayanjae8652@gmail.com", + // "pass": "lorenarosamond4075", + // "auxiliary": "lorenarosamond8958@outlook.com", + // "index": 2, + // "id": "bayanjae8652@gmail.com", + // "info": "成功😘", + // "ident": "poe-validate", + // "type": "fail", + // "result": "成功😘" + // }, + // { + // "user": "geneviashametra1019@gmail.com", + // "pass": "sheypervis2156", + // "auxiliary": "sheypervis0163@qq.com", + // "index": 3, + // "id": "geneviashametra1019@gmail.com", + // "info": "成功😘", + // "ident": "poe-validate", + // "type": "success", + // "result": "成功😘" + // }, + // { + // "user": "marikamelindasue5911@gmail.com", + // "pass": "ambrbreeann4103", + // "auxiliary": "ambrbreeann5643@icloud.com", + // "index": 4, + // "id": "marikamelindasue5911@gmail.com", + // "info": "成功😘", + // "ident": "poe-validate", + // "type": "success", + // "result": "成功😘" + // }, + // { + // "user": "caterinereba2981@gmail.com", + // "pass": "arvisleo0563", + // "auxiliary": "arvisleo1265@zoho.com", + // "index": 5, + // "id": "caterinereba2981@gmail.com", + // "info": "成功😘", + // "ident": "poe-validate", + // "type": "success", + // "result": "成功😘" + // }, + // { + // "user": "adairaderrell9992@gmail.com", + // "pass": "adairaderrell8698", + // "auxiliary": "adairaderrell1859@hotmail.com", + // "index": 6, + // "id": "adairaderrell9992@gmail.com", + // "info": "成功😘", + // "ident": "poe-validate", + // "type": "success", + // "result": "成功😘" + // }, + // { + // "user": "nishadarrow0444@gmail.com", + // "pass": "cliftontiffani7462", + // "auxiliary": "cliftontiffani2263@hotmail.com", + // "index": 7, + // "id": "nishadarrow0444@gmail.com", + // "info": "成功😘", + // "ident": "poe-validate", + // "type": "success", + // "result": "成功😘" + // } ]) ipcRenderer.on('progress', (event, args) => { @@ -142,8 +143,8 @@ const listFail = computed(() => { }) const { copy } = useClipboard() -function copyText(item: any) { - copy(item.user + '----' + (item.result || '')) +function copyText(text: any) { + copy(text) } function copyAccount(item: any) { copy(item.user + '----' + item.pass + '----' + item.auxiliary)