feat: enhance signup flow to skip profile step for logged-in users

This commit is contained in:
QLHazyCoder
2026-04-25 17:35:22 +08:00
parent 809d146b74
commit 171b375a0b
6 changed files with 286 additions and 7 deletions
+118 -6
View File
@@ -1098,6 +1098,67 @@ function isStep5Ready() {
);
}
function isSignupProfilePageUrl(rawUrl = location.href) {
const url = String(rawUrl || '').trim();
if (!url) {
return false;
}
try {
const parsed = new URL(url);
const host = String(parsed.hostname || '').toLowerCase();
if (!['auth.openai.com', 'auth0.openai.com', 'accounts.openai.com'].includes(host)) {
return false;
}
return /\/create-account\/profile(?:[/?#]|$)/i.test(String(parsed.pathname || ''));
} catch {
return false;
}
}
function isLikelyLoggedInChatgptHomeUrl(rawUrl = location.href) {
const url = String(rawUrl || '').trim();
if (!url) {
return false;
}
try {
const parsed = new URL(url);
const host = String(parsed.hostname || '').toLowerCase();
if (!['chatgpt.com', 'www.chatgpt.com', 'chat.openai.com'].includes(host)) {
return false;
}
const path = String(parsed.pathname || '');
if (/^\/(?:auth\/|create-account\/|email-verification|log-in|add-phone)(?:[/?#]|$)/i.test(path)) {
return false;
}
return true;
} catch {
return false;
}
}
function getStep4PostVerificationState() {
if (isStep5Ready() || isSignupProfilePageUrl()) {
return {
state: 'step5',
url: location.href,
};
}
if (isLikelyLoggedInChatgptHomeUrl()) {
return {
state: 'logged_in_home',
skipProfileStep: true,
url: location.href,
};
}
return null;
}
function getPageTextSnapshot() {
return (document.body?.innerText || document.body?.textContent || '')
.replace(/\s+/g, ' ')
@@ -2056,10 +2117,19 @@ function isSignupEmailAlreadyExistsPage() {
}
function inspectSignupVerificationState() {
if (isStep5Ready()) {
const postVerificationState = getStep4PostVerificationState();
if (postVerificationState?.state === 'step5') {
return { state: 'step5' };
}
if (postVerificationState?.state === 'logged_in_home') {
return {
state: 'logged_in_home',
skipProfileStep: true,
url: postVerificationState.url || location.href,
};
}
if (isSignupPasswordErrorPage()) {
const timeoutPage = getSignupPasswordTimeoutErrorPageState();
return {
@@ -2096,7 +2166,13 @@ async function waitForSignupVerificationTransition(timeout = 5000) {
throwIfStopped();
const snapshot = inspectSignupVerificationState();
if (snapshot.state === 'step5' || snapshot.state === 'verification' || snapshot.state === 'error' || snapshot.state === 'email_exists') {
if (
snapshot.state === 'step5'
|| snapshot.state === 'logged_in_home'
|| snapshot.state === 'verification'
|| snapshot.state === 'error'
|| snapshot.state === 'email_exists'
) {
return snapshot;
}
@@ -2128,6 +2204,20 @@ async function prepareSignupVerificationFlow(payload = {}, timeout = 30000) {
return { ready: true, alreadyVerified: true, retried: recoveryRound, prepareSource };
}
if (snapshot.state === 'logged_in_home') {
/*
log(`${prepareLogLabel}锛氶〉闈㈠凡鐩存帴杩涘叆 ChatGPT 宸茬櫥褰曟€侊紝鏈楠?鎸夊凡瀹屾垚澶勭悊锛屽苟灏嗚烦杩囨楠?5銆俙, 'ok');
*/
log(`${prepareLogLabel}:页面已直接进入 ChatGPT 已登录态,本步骤按已完成处理,并将跳过步骤 5。`, 'ok');
return {
ready: true,
alreadyVerified: true,
skipProfileStep: true,
retried: recoveryRound,
prepareSource,
};
}
if (snapshot.state === 'verification') {
log(`${prepareLogLabel}:验证码页面已就绪${recoveryRound ? `(期间自动恢复 ${recoveryRound} 次)` : ''}`, 'ok');
return { ready: true, retried: recoveryRound, prepareSource };
@@ -2215,15 +2305,25 @@ async function waitForVerificationSubmitOutcome(step, timeout) {
continue;
}
if (step === 4) {
const postVerificationState = getStep4PostVerificationState();
if (postVerificationState?.state === 'logged_in_home') {
return {
success: true,
skipProfileStep: true,
url: postVerificationState.url || location.href,
};
}
if (postVerificationState?.state === 'step5') {
return { success: true };
}
}
const errorText = getVerificationErrorText();
if (errorText) {
return { invalidCode: true, errorText };
}
if (step === 4 && isStep5Ready()) {
return { success: true };
}
if (step === 8 && isStep8Ready()) {
return { success: true };
}
@@ -2240,6 +2340,18 @@ async function waitForVerificationSubmitOutcome(step, timeout) {
if (signupRetryState?.userAlreadyExistsBlocked) {
throw createSignupUserAlreadyExistsError();
}
const postVerificationState = getStep4PostVerificationState();
if (postVerificationState?.state === 'logged_in_home') {
return {
success: true,
skipProfileStep: true,
url: postVerificationState.url || location.href,
};
}
if (postVerificationState?.state === 'step5') {
return { success: true };
}
}
if (isVerificationPageStillVisible()) {