Files
FlowPilot/background/steps/step5.js
T
QLHazyCoder 4f12d67d9f feat: implement multi-step background process for user registration
- Add step 1: Open ChatGPT homepage and prepare for signup.
- Add step 2: Handle email submission and ensure the signup entry page is ready.
- Add step 3: Fill in the password using either a custom or generated password.
- Add step 4: Confirm the registration verification page and handle email verification.
- Add step 5: Generate random user details and handle onboarding redirection.
- Add step 6: Manage OAuth login process and handle login verification.
- Add step 7: Retrieve verification code from email and manage retries.
- Add step 8: Handle consent page interactions and manage callback URLs.
- Add step 9: Submit callback information to CPA or SUB2API based on user settings.
- Implement tests to ensure all steps are correctly imported and functional.
2026-04-16 23:38:43 +08:00

70 lines
2.2 KiB
JavaScript

(function attachBackgroundStep5(root, factory) {
root.MultiPageBackgroundStep5 = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createBackgroundStep5Module() {
function createStep5Executor(deps = {}) {
const {
addLog,
generateRandomBirthday,
generateRandomName,
getTabId,
handleChatgptOnboardingSkip,
isRetryableContentScriptTransportError,
LOG_PREFIX,
sendToContentScript,
waitForStep5ChatgptRedirect,
} = deps;
async function executeStep5() {
const { firstName, lastName } = generateRandomName();
const { year, month, day } = generateRandomBirthday();
await addLog(`步骤 5:已生成姓名 ${firstName} ${lastName},生日 ${year}-${month}-${day}`);
let step5Result = null;
let step5TransportError = null;
try {
step5Result = await sendToContentScript('signup-page', {
type: 'EXECUTE_STEP',
step: 5,
source: 'background',
payload: { firstName, lastName, year, month, day },
});
} catch (err) {
if (isRetryableContentScriptTransportError(err)) {
step5TransportError = err;
console.log(LOG_PREFIX, '步骤 5:内容脚本通信中断,正在检查是否跳转到 ChatGPT 引导页...', err?.message);
} else {
throw err;
}
}
if (step5Result?.chatgptOnboarding) {
await addLog('步骤 5:检测到 ChatGPT 引导页跳转,正在处理引导页跳过...');
await handleChatgptOnboardingSkip();
return;
}
if (step5Result?.chatgptHome) {
await addLog('步骤 5:检测到已进入 ChatGPT 页面,注册成功。', 'ok');
return;
}
if (step5TransportError) {
const signupTabId = await getTabId('signup-page');
const redirectedTab = await waitForStep5ChatgptRedirect(signupTabId);
if (redirectedTab) {
await addLog('步骤 5:内容脚本因页面跳转到 ChatGPT 而断开,正在处理引导页跳过...');
await handleChatgptOnboardingSkip(redirectedTab.id);
return;
}
throw step5TransportError;
}
}
return { executeStep5 };
}
return { createStep5Executor };
});