fix basic start chat logic since website upgrade

This commit is contained in:
geekgeekrun
2025-04-25 00:31:57 +08:00
parent 5dc7250634
commit ccbc717a45
@@ -409,7 +409,7 @@ async function toRecommendPage (hooks) {
} }
} }
const INIT_START_EXCEPT_JOB_INDEX = 1 const INIT_START_EXCEPT_JOB_INDEX = 0
let currentExceptJobIndex = INIT_START_EXCEPT_JOB_INDEX let currentExceptJobIndex = INIT_START_EXCEPT_JOB_INDEX
afterPageLoad: while (true) { afterPageLoad: while (true) {
let expectJobList let expectJobList
@@ -422,20 +422,21 @@ async function toRecommendPage (hooks) {
await sleepWithRandomDelay(2500) await sleepWithRandomDelay(2500)
await Promise.all([ await Promise.all([
page.waitForSelector('.job-recommend-main .recommend-search-expect .recommend-job-btn'), page.waitForSelector('.c-expect-select .expect-list .expect-item'),
page.waitForSelector('.job-list-container .rec-job-list') page.waitForSelector('.job-list-container .rec-job-list')
]) ])
await page.click(`.c-expect-select .expect-list .expect-item`)
const currentActiveJobIndex = await page.evaluate(` const currentActiveJobIndex = await page.evaluate(`
[...document.querySelectorAll('.job-recommend-main .recommend-search-expect .recommend-job-btn')].findIndex(it => it.classList.contains('active')) [...document.querySelectorAll('.c-expect-select .expect-list .expect-item')].findIndex(it => it.classList.contains('active'))
`) `)
expectJobList = await page.evaluate(`document.querySelector('.job-recommend-search')?.__vue__?.expectList`) expectJobList = await page.evaluate(`document.querySelector('.c-expect-select')?.__vue__?.expectList`)
if (currentActiveJobIndex === currentExceptJobIndex) { if (currentActiveJobIndex === currentExceptJobIndex) {
// first navigation and can immediately start chat (recommend job) // first navigation and can immediately start chat (recommend job)
} else { } else {
// not first navigation and should choose a job (except job) // not first navigation and should choose a job (except job)
// click first expect job // click first expect job
const expectJobTabHandlers = await page.$$('.job-recommend-main .recommend-search-expect .recommend-job-btn') const expectJobTabHandlers = await page.$$('.c-expect-select .expect-list .expect-item')
await expectJobTabHandlers[currentExceptJobIndex].click() await expectJobTabHandlers[currentExceptJobIndex].click()
await page.waitForResponse( await page.waitForResponse(
response => { response => {
@@ -486,7 +487,7 @@ async function toRecommendPage (hooks) {
// job list // job list
const recommendJobListElProxy = await page.$('.job-list-container .rec-job-list') const recommendJobListElProxy = await page.$('.job-list-container .rec-job-list')
let jobListData = await page.evaluate(`document.querySelector('.job-recommend-main')?.__vue__?.jobList`) let jobListData = await page.evaluate(`document.querySelector('.page-jobs-main')?.__vue__?.jobList`)
let hasReachLastPage = false let hasReachLastPage = false
let targetJobIndex = -1 let targetJobIndex = -1
let targetJobData let targetJobData
@@ -522,7 +523,7 @@ async function toRecommendPage (hooks) {
await sleep(1) await sleep(1)
await requestNextPagePromiseWithResolver?.promise await requestNextPagePromiseWithResolver?.promise
hasReachLastPage = await page.evaluate(` hasReachLastPage = await page.evaluate(`
!(document.querySelector('.job-recommend-main')?.__vue__?.hasMore) !(document.querySelector('.page-jobs-main')?.__vue__?.hasMore)
`) `)
if (hasReachLastPage) { if (hasReachLastPage) {
console.log(`Arrive the terminal of the job list.`) console.log(`Arrive the terminal of the job list.`)
@@ -533,7 +534,7 @@ async function toRecommendPage (hooks) {
await sleep(3000) await sleep(3000)
jobListData = await page.evaluate( jobListData = await page.evaluate(
` `
document.querySelector('.job-recommend-main')?.__vue__?.jobList document.querySelector('.page-jobs-main')?.__vue__?.jobList
` `
) )
tempTargetJobIndexToCheckDetail = jobListData.findIndex(it => tempTargetJobIndexToCheckDetail = jobListData.findIndex(it =>
@@ -568,6 +569,10 @@ async function toRecommendPage (hooks) {
const recommendJobItemList = await recommendJobListElProxy.$$('ul.rec-job-list li.job-card-box') const recommendJobItemList = await recommendJobListElProxy.$$('ul.rec-job-list li.job-card-box')
const targetJobElProxy = recommendJobItemList[tempTargetJobIndexToCheckDetail] const targetJobElProxy = recommendJobItemList[tempTargetJobIndexToCheckDetail]
// click that element // click that element
await page.evaluate(() => {
document.documentElement.scrollTop = 0
})
await sleep(500)
await targetJobElProxy.click() await targetJobElProxy.click()
await page.waitForResponse( await page.waitForResponse(
response => { response => {
@@ -670,6 +675,10 @@ async function toRecommendPage (hooks) {
await hooks.newChatWillStartup?.promise(targetJobData) await hooks.newChatWillStartup?.promise(targetJobData)
const startChatButtonProxy = await page.$('.job-detail-box .op-btn.op-btn-chat') const startChatButtonProxy = await page.$('.job-detail-box .op-btn.op-btn-chat')
await page.evaluate(() => {
document.documentElement.scrollTop = 0
})
await sleep(500)
//#region click the chat button //#region click the chat button
await startChatButtonProxy.click() await startChatButtonProxy.click()