Files
FlowPilot/background/steps/fill-profile.js
T
QLHazyCoder 33c5f759d9 feat: refactor user registration steps into modular functions and implement step registry
- Replaced individual step imports with a centralized step registry in background.js
- Created separate modules for each registration step: open-chatgpt, submit-signup-email, fill-password, fetch-signup-code, fill-profile, oauth-login, fetch-login-code, confirm-oauth, platform-verify
- Updated tests to reflect changes in step imports and added new tests for step registry functionality
2026-04-16 23:56:57 +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 };
});