Skip to content

Commit

Permalink
添加无法签到逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
haixiangyan committed May 7, 2020
1 parent 48435ca commit 8196f5c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {initUserCache, sleep} from './lib/tool'

// 启动浏览器
loading.start('启动无头浏览器')
const browser = await puppeteer.launch({defaultViewport: null})
const browser = await puppeteer.launch({
headless: process.env.NODE_ENV !== 'development',
defaultViewport: null
})
const page = await browser.newPage()
loading.stop() && consola.success('成功启动无头浏览器')

Expand Down
1 change: 1 addition & 0 deletions constants/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export const usernameInput = '#ls_username'
export const passwordInput = '#ls_password'
export const loginButton = '#lsform > div > div.y.pns > table > tbody > tr:nth-child(3) > td:nth-child(2) > button'
export const usernameSpan = '#um > p:nth-child(2) > strong'

// 签到
export const startCheckinAnchor = '#um > p:nth-child(3) > a:nth-child(3)'
Expand Down
4 changes: 2 additions & 2 deletions logic/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as fs from 'fs'
import * as inquirer from 'inquirer'
import consola from 'consola'
import {Page} from 'puppeteer'
import {loginButton, passwordInput, startCheckinAnchor, usernameInput} from '../constants/selectors'
import {loginButton, passwordInput, usernameInput, usernameSpan} from '../constants/selectors'
import {userPath} from '../constants/paths'
import {userQuestion} from '../constants/questions'
import {readJSONSync, sleep} from '../lib/tool'
Expand Down Expand Up @@ -30,7 +30,7 @@ export const login = async (page: Page, username: string, password: string) => {

await sleep(3000)
// 登录失败
if (await page.$(startCheckinAnchor) === null) {
if (await page.$(usernameSpan) === null) {
loading.stop() && consola.error('登录失败')

const newUser = await askUser()
Expand Down
6 changes: 6 additions & 0 deletions logic/checkin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import {Page} from 'puppeteer'
import {autoModeRadioInput, checkinBtn, startCheckinAnchor, 开心} from '../constants/selectors'
import {sleep} from '../lib/tool'
import loading from '../lib/loading'
import consola from 'consola'

const checkin = async (page: Page) => {
if (await page.$(startCheckinAnchor) === null) {
return loading.stop() && consola.error('无法签到')
}

// 开始签到
await page.click(startCheckinAnchor)
await sleep(1000)
Expand Down

0 comments on commit 8196f5c

Please sign in to comment.