merge: sync latest dev into sub2api branch
This commit is contained in:
+57
-14
@@ -188,6 +188,12 @@ async function prepareLoginCodeFlow(timeout = 15000) {
|
||||
return { ready: true, mode: 'verification_page' };
|
||||
}
|
||||
|
||||
const initialRestartSignal = getStep7RestartFromStep6Signal();
|
||||
if (initialRestartSignal) {
|
||||
log('步骤 7:检测到登录页超时报错,准备回到步骤 6 重新发起登录验证码流程...', 'warn');
|
||||
return initialRestartSignal;
|
||||
}
|
||||
|
||||
const start = Date.now();
|
||||
let switchClickCount = 0;
|
||||
let lastSwitchAttemptAt = 0;
|
||||
@@ -212,6 +218,12 @@ async function prepareLoginCodeFlow(timeout = 15000) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const restartSignal = getStep7RestartFromStep6Signal();
|
||||
if (restartSignal) {
|
||||
log('步骤 7:检测到登录页超时报错,准备回到步骤 6 重新发起登录验证码流程...', 'warn');
|
||||
return restartSignal;
|
||||
}
|
||||
|
||||
const passwordInput = document.querySelector('input[type="password"]');
|
||||
const switchTrigger = findOneTimeCodeLoginTrigger();
|
||||
|
||||
@@ -239,7 +251,10 @@ async function prepareLoginCodeFlow(timeout = 15000) {
|
||||
|
||||
async function resendVerificationCode(step, timeout = 45000) {
|
||||
if (step === 7) {
|
||||
await prepareLoginCodeFlow();
|
||||
const prepareResult = await prepareLoginCodeFlow();
|
||||
if (prepareResult?.restartFromStep6) {
|
||||
return prepareResult;
|
||||
}
|
||||
}
|
||||
|
||||
const start = Date.now();
|
||||
@@ -382,8 +397,8 @@ const VERIFICATION_PAGE_PATTERN = /检查您的收件箱|输入我们刚刚向|
|
||||
const OAUTH_CONSENT_PAGE_PATTERN = /使用\s*ChatGPT\s*登录到\s*Codex|login\s+to\s+codex|log\s+in\s+to\s+codex|authorize|授权/i;
|
||||
const ADD_PHONE_PAGE_PATTERN = /add[\s-]*phone|添加手机号|手机号码|手机号|phone\s+number|telephone/i;
|
||||
const STEP5_SUBMIT_ERROR_PATTERN = /无法根据该信息创建帐户|请重试|unable\s+to\s+create\s+(?:your\s+)?account|couldn'?t\s+create\s+(?:your\s+)?account|something\s+went\s+wrong|invalid\s+(?:birthday|birth|date)|生日|出生日期/i;
|
||||
const SIGNUP_PASSWORD_ERROR_TITLE_PATTERN = /糟糕,出错了|something\s+went\s+wrong|oops/i;
|
||||
const SIGNUP_PASSWORD_ERROR_DETAIL_PATTERN = /operation\s+timed\s+out|timed\s+out|请求超时|操作超时/i;
|
||||
const AUTH_TIMEOUT_ERROR_TITLE_PATTERN = /糟糕,出错了|something\s+went\s+wrong|oops/i;
|
||||
const AUTH_TIMEOUT_ERROR_DETAIL_PATTERN = /operation\s+timed\s+out|timed\s+out|请求超时|操作超时/i;
|
||||
const SIGNUP_EMAIL_EXISTS_PATTERN = /与此电子邮件地址相关联的帐户已存在|account\s+associated\s+with\s+this\s+email\s+address\s+already\s+exists|email\s+address.*already\s+exists/i;
|
||||
|
||||
function getVerificationErrorText() {
|
||||
@@ -466,6 +481,10 @@ function isAddPhonePageReady() {
|
||||
return ADD_PHONE_PAGE_PATTERN.test(getPageTextSnapshot());
|
||||
}
|
||||
|
||||
function isLoginPage() {
|
||||
return /\/log-in(?:[/?#]|$)/i.test(location.pathname || '');
|
||||
}
|
||||
|
||||
function isStep8Ready() {
|
||||
const continueBtn = getPrimaryContinueButton();
|
||||
if (!continueBtn) return false;
|
||||
@@ -610,31 +629,52 @@ function getSignupPasswordSubmitButton({ allowDisabled = false } = {}) {
|
||||
}) || null;
|
||||
}
|
||||
|
||||
function getSignupRetryButton() {
|
||||
function getAuthRetryButton({ allowDisabled = false } = {}) {
|
||||
const direct = document.querySelector('button[data-dd-action-name="Try again"]');
|
||||
if (direct && isVisibleElement(direct) && isActionEnabled(direct)) {
|
||||
if (direct && isVisibleElement(direct) && (allowDisabled || isActionEnabled(direct))) {
|
||||
return direct;
|
||||
}
|
||||
|
||||
const candidates = document.querySelectorAll('button, [role="button"]');
|
||||
return Array.from(candidates).find((el) => {
|
||||
if (!isVisibleElement(el) || !isActionEnabled(el)) return false;
|
||||
if (!isVisibleElement(el) || (!allowDisabled && !isActionEnabled(el))) return false;
|
||||
const text = getActionText(el);
|
||||
return /重试|try\s+again/i.test(text);
|
||||
}) || null;
|
||||
}
|
||||
|
||||
function isSignupPasswordErrorPage() {
|
||||
if (!isSignupPasswordPage()) return false;
|
||||
function matchesAuthTimeoutErrorPage(pathPattern) {
|
||||
if (!pathPattern.test(location.pathname || '')) return false;
|
||||
const text = getPageTextSnapshot();
|
||||
return Boolean(
|
||||
getSignupRetryButton()
|
||||
&& (SIGNUP_PASSWORD_ERROR_TITLE_PATTERN.test(text)
|
||||
|| SIGNUP_PASSWORD_ERROR_DETAIL_PATTERN.test(text)
|
||||
|| SIGNUP_PASSWORD_ERROR_TITLE_PATTERN.test(document.title || ''))
|
||||
getAuthRetryButton({ allowDisabled: true })
|
||||
&& (AUTH_TIMEOUT_ERROR_TITLE_PATTERN.test(text)
|
||||
|| AUTH_TIMEOUT_ERROR_DETAIL_PATTERN.test(text)
|
||||
|| AUTH_TIMEOUT_ERROR_TITLE_PATTERN.test(document.title || ''))
|
||||
);
|
||||
}
|
||||
|
||||
function isSignupPasswordErrorPage() {
|
||||
return matchesAuthTimeoutErrorPage(/\/create-account\/password(?:[/?#]|$)/i);
|
||||
}
|
||||
|
||||
function buildStep7RestartFromStep6Marker(reason, url = location.href) {
|
||||
return `STEP7_RESTART_FROM_STEP6::${reason || 'unknown'}::${url || ''}`;
|
||||
}
|
||||
|
||||
function getStep7RestartFromStep6Signal() {
|
||||
if (!isLoginPage() || !matchesAuthTimeoutErrorPage(/\/log-in(?:[/?#]|$)/i)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
error: buildStep7RestartFromStep6Marker('login_timeout_error_page', location.href),
|
||||
restartFromStep6: true,
|
||||
reason: 'login_timeout_error_page',
|
||||
url: location.href,
|
||||
};
|
||||
}
|
||||
|
||||
function isSignupEmailAlreadyExistsPage() {
|
||||
return isSignupPasswordPage() && SIGNUP_EMAIL_EXISTS_PATTERN.test(getPageTextSnapshot());
|
||||
}
|
||||
@@ -651,7 +691,7 @@ function inspectSignupVerificationState() {
|
||||
if (isSignupPasswordErrorPage()) {
|
||||
return {
|
||||
state: 'error',
|
||||
retryButton: getSignupRetryButton(),
|
||||
retryButton: getAuthRetryButton({ allowDisabled: true }),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -804,7 +844,10 @@ async function fillVerificationCode(step, payload) {
|
||||
log(`步骤 ${step}:正在填写验证码:${code}`);
|
||||
|
||||
if (step === 7) {
|
||||
await prepareLoginCodeFlow();
|
||||
const prepareResult = await prepareLoginCodeFlow();
|
||||
if (prepareResult?.restartFromStep6) {
|
||||
return prepareResult;
|
||||
}
|
||||
}
|
||||
|
||||
// Find code input — could be a single input or multiple separate inputs
|
||||
|
||||
Reference in New Issue
Block a user