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
This commit is contained in:
QLHazyCoder
2026-04-16 23:56:57 +08:00
parent 4f12d67d9f
commit 33c5f759d9
14 changed files with 91 additions and 32 deletions
+60
View File
@@ -0,0 +1,60 @@
(function attachBackgroundStep3(root, factory) {
root.MultiPageBackgroundStep3 = factory();
})(typeof self !== 'undefined' ? self : globalThis, function createBackgroundStep3Module() {
function createStep3Executor(deps = {}) {
const {
addLog,
chrome,
ensureContentScriptReadyOnTab,
generatePassword,
getTabId,
isTabAlive,
sendToContentScript,
setPasswordState,
setState,
SIGNUP_PAGE_INJECT_FILES,
} = deps;
async function executeStep3(state) {
const resolvedEmail = state.email;
if (!resolvedEmail) {
throw new Error('缺少邮箱地址,请先完成步骤 2。');
}
const signupTabId = await getTabId('signup-page');
if (!signupTabId || !(await isTabAlive('signup-page'))) {
throw new Error('认证页面标签页已关闭,请先重新完成步骤 2。');
}
const password = state.customPassword || generatePassword();
await setPasswordState(password);
const accounts = state.accounts || [];
accounts.push({ email: resolvedEmail, password, createdAt: new Date().toISOString() });
await setState({ accounts });
await chrome.tabs.update(signupTabId, { active: true });
await ensureContentScriptReadyOnTab('signup-page', signupTabId, {
inject: SIGNUP_PAGE_INJECT_FILES,
injectSource: 'signup-page',
timeoutMs: 45000,
retryDelayMs: 900,
logMessage: '步骤 3:密码页内容脚本未就绪,正在等待页面恢复...',
});
await addLog(
`步骤 3:正在填写密码,邮箱为 ${resolvedEmail},密码为${state.customPassword ? '自定义' : '自动生成'}${password.length} 位)`
);
await sendToContentScript('signup-page', {
type: 'EXECUTE_STEP',
step: 3,
source: 'background',
payload: { email: resolvedEmail, password },
});
}
return { executeStep3 };
}
return { createStep3Executor };
});