From 2aee76307f653126043d0522f16383e32ca44096 Mon Sep 17 00:00:00 2001 From: geekgeekrun Date: Sun, 14 Dec 2025 11:15:22 +0800 Subject: [PATCH] add sage time gtag in main process --- .../geek-auto-start-chat-with-boss/index.mjs | 33 ++++++++++++------- .../sage-time.mjs | 13 +++++++- .../main.mjs | 4 ++- .../index.ts | 4 ++- packages/ui/src/main/utils/gtag/GtagPlugin.ts | 6 ++++ 5 files changed, 46 insertions(+), 14 deletions(-) diff --git a/packages/geek-auto-start-chat-with-boss/index.mjs b/packages/geek-auto-start-chat-with-boss/index.mjs index 27e0829..0d62cc2 100644 --- a/packages/geek-auto-start-chat-with-boss/index.mjs +++ b/packages/geek-auto-start-chat-with-boss/index.mjs @@ -740,7 +740,8 @@ async function toRecommendPage (hooks) { await storeStorage(page).catch(() => void 0) await sleepWithRandomDelay(2000) await waitForSageTimeOrJustContinue({ - tag: 'afterJobSourceChosen' + tag: 'afterJobSourceChosen', + hooks }) } await sleepWithRandomDelay(1500) @@ -936,7 +937,8 @@ async function toRecommendPage (hooks) { } requestNextPagePromiseWithResolver = null await waitForSageTimeOrJustContinue({ - tag: 'afterJobListPageFetched' + tag: 'afterJobListPageFetched', + hooks }) await sleep(5000) await updateJobListData() @@ -982,7 +984,8 @@ async function toRecommendPage (hooks) { await sleepWithRandomDelay(2000) } await waitForSageTimeOrJustContinue({ - tag: 'afterJobDetailFetched' + tag: 'afterJobDetailFetched', + hooks }) targetJobData = await page.evaluate('document.querySelector(".job-detail-box").__vue__.data') selectedJobData = await page.evaluate('document.querySelector(".page-jobs-main").__vue__.currentJob') @@ -1012,7 +1015,8 @@ async function toRecommendPage (hooks) { else if (jobNotActiveStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_BOSS) { try { await waitForSageTimeOrJustContinue({ - tag: 'beforeJobNotSuitMarked' + tag: 'beforeJobNotSuitMarked', + hooks }) const { chosenReasonInUi } = await markJobAsNotSuitInRecommendPage(MarkAsNotSuitReason.BOSS_INACTIVE) await hooks.jobMarkedAsNotSuit.promise( @@ -1053,7 +1057,8 @@ async function toRecommendPage (hooks) { else if (expectCityNotMatchStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_BOSS) { try { await waitForSageTimeOrJustContinue({ - tag: 'beforeJobNotSuitMarked' + tag: 'beforeJobNotSuitMarked', + hooks }) const { chosenReasonInUi } = await markJobAsNotSuitInRecommendPage(MarkAsNotSuitReason.JOB_CITY_NOT_SUIT) await hooks.jobMarkedAsNotSuit.promise( @@ -1093,7 +1098,8 @@ async function toRecommendPage (hooks) { else if (expectWorkExpNotMatchStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_BOSS) { try { await waitForSageTimeOrJustContinue({ - tag: 'beforeJobNotSuitMarked' + tag: 'beforeJobNotSuitMarked', + hooks }) const { chosenReasonInUi } = await markJobAsNotSuitInRecommendPage(MarkAsNotSuitReason.JOB_WORK_EXP_NOT_SUIT) await hooks.jobMarkedAsNotSuit.promise( @@ -1133,7 +1139,8 @@ async function toRecommendPage (hooks) { else if (jobNotMatchStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_BOSS) { try { await waitForSageTimeOrJustContinue({ - tag: 'beforeJobNotSuitMarked' + tag: 'beforeJobNotSuitMarked', + hooks }) const { chosenReasonInUi } = await markJobAsNotSuitInRecommendPage(MarkAsNotSuitReason.JOB_NOT_SUIT) await hooks.jobMarkedAsNotSuit.promise( @@ -1176,7 +1183,8 @@ async function toRecommendPage (hooks) { else if (expectSalaryNotMatchStrategy === MarkAsNotSuitOp.MARK_AS_NOT_SUIT_ON_BOSS) { try { await waitForSageTimeOrJustContinue({ - tag: 'beforeJobNotSuitMarked' + tag: 'beforeJobNotSuitMarked', + hooks }) const { chosenReasonInUi } = await markJobAsNotSuitInRecommendPage(MarkAsNotSuitReason.JOB_SALARY_NOT_SUIT) await hooks.jobMarkedAsNotSuit.promise( @@ -1296,7 +1304,8 @@ async function toRecommendPage (hooks) { } }) await waitForSageTimeOrJustContinue({ - tag: 'beforeJobChatStartup' + tag: 'beforeJobChatStartup', + hooks }) await sleepWithRandomDelay(1000) const startChatButtonInnerHTML = await page.evaluate('document.querySelector(".job-detail-box .op-btn.op-btn-chat")?.innerHTML.trim()') @@ -1347,7 +1356,8 @@ async function toRecommendPage (hooks) { /剩\d+次沟通机会/.test(res.zpData.bizData?.chatRemindDialog?.content) ) { await waitForSageTimeOrJustContinue({ - tag: 'beforeJobChatStartupAfterTwiceConfirm' + tag: 'beforeJobChatStartupAfterTwiceConfirm', + hooks }) const confirmButton = await page.waitForSelector('.chat-block-dialog .chat-block-footer .sure-btn') await confirmButton.click() @@ -1359,7 +1369,8 @@ async function toRecommendPage (hooks) { /猎头/.test(res.zpData.bizData?.chatRemindDialog?.content) ) { await waitForSageTimeOrJustContinue({ - tag: 'beforeJobChatStartupAfterTwiceConfirm' + tag: 'beforeJobChatStartupAfterTwiceConfirm', + hooks }) const confirmButton = await page.waitForSelector(`xpath///*[contains(@class, "chat-block-dialog")]//*[contains(@class, "chat-block-footer")]//*[contains(text(), "继续")]`) await confirmButton.click() diff --git a/packages/geek-auto-start-chat-with-boss/sage-time.mjs b/packages/geek-auto-start-chat-with-boss/sage-time.mjs index 5a6445d..8c405b4 100644 --- a/packages/geek-auto-start-chat-with-boss/sage-time.mjs +++ b/packages/geek-auto-start-chat-with-boss/sage-time.mjs @@ -23,7 +23,8 @@ if (parseFloat(sageTimePauseMinute) === 0) { let totalEnabledTimes = 0 let recordedOpCount = 0 export const waitForSageTimeOrJustContinue = async ({ - tag + tag, + hooks, } = {}) => { if (!isSageTimeEnabled) { return @@ -32,8 +33,18 @@ export const waitForSageTimeOrJustContinue = async ({ if (recordedOpCount > sageTimeOpTimes) { totalEnabledTimes++ console.log(`[SageTime${tagText}] 请求已达限制,开启;当前记录次数 ${recordedOpCount};第 ${totalEnabledTimes} 次开启`) + await hooks?.sageTimeEnter?.promise({ + tag, + totalEnabledTimes, + recordedOpCount, + }) await sleep(sageTimePauseMinute * 60 * 1000) console.log(`[SageTime${tagText}] 请求限制已解除,关闭;当前记录次数 ${recordedOpCount};第 ${totalEnabledTimes} 次关闭`) + await hooks?.sageTimeExit?.promise({ + tag, + totalEnabledTimes, + recordedOpCount, + }) recordedOpCount = 0 } else { diff --git a/packages/run-core-of-geek-auto-start-chat-with-boss/main.mjs b/packages/run-core-of-geek-auto-start-chat-with-boss/main.mjs index 7945286..8b75b90 100644 --- a/packages/run-core-of-geek-auto-start-chat-with-boss/main.mjs +++ b/packages/run-core-of-geek-auto-start-chat-with-boss/main.mjs @@ -57,7 +57,9 @@ const main = async () => { noPositionFoundForCurrentJob: new SyncHook(), noPositionFoundAfterTraverseAllJob: new SyncHook(), errorEncounter: new SyncHook(['errorInfo']), - encounterEmptyRecommendJobList: new AsyncSeriesHook(['args']) + encounterEmptyRecommendJobList: new AsyncSeriesHook(['args']), + sageTimeEnter: new AsyncSeriesHook(['args']), + sageTimeExit: new AsyncSeriesHook(['args']) } initPlugins(hooks) await hooks.daemonInitialized.callAsync() diff --git a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_MAIN/index.ts b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_MAIN/index.ts index f93a9c8..1387f1f 100644 --- a/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_MAIN/index.ts +++ b/packages/ui/src/main/flow/GEEK_AUTO_START_CHAT_WITH_BOSS_MAIN/index.ts @@ -94,7 +94,9 @@ const runAutoChat = async () => { noPositionFoundForCurrentJob: new SyncHook(), noPositionFoundAfterTraverseAllJob: new SyncHook(), errorEncounter: new SyncHook(['errorInfo']), - encounterEmptyRecommendJobList: new AsyncSeriesHook(['args']) + encounterEmptyRecommendJobList: new AsyncSeriesHook(['args']), + sageTimeEnter: new AsyncSeriesHook(['args']), + sageTimeExit: new AsyncSeriesHook(['args']) } initPlugins(hooks) diff --git a/packages/ui/src/main/utils/gtag/GtagPlugin.ts b/packages/ui/src/main/utils/gtag/GtagPlugin.ts index de3c28e..2a4170a 100644 --- a/packages/ui/src/main/utils/gtag/GtagPlugin.ts +++ b/packages/ui/src/main/utils/gtag/GtagPlugin.ts @@ -31,5 +31,11 @@ export default class GtagPlugin { hooks.encounterEmptyRecommendJobList.tap('GtagPlugin', ({ pageQuery }) => { gtag('encounter_empty_rec_job_list', { pageQuery }) }) + hooks.sageTimeEnter.tap('GtagPlugin', ({ tag, totalEnabledTimes, recordedOpCount }) => { + gtag('sage_time_enter', { tag, totalEnabledTimes, recordedOpCount }) + }) + hooks.sageTimeExit.tap('GtagPlugin', ({ tag, totalEnabledTimes, recordedOpCount }) => { + gtag('sage_time_exit', { tag, totalEnabledTimes, recordedOpCount }) + }) } }