diff --git a/README.md b/README.md index 1899a4c..c954718 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,7 @@ python3 scripts/hotmail_helper.py Hotmail helper listening on http://127.0.0.1:17373 ``` -同时还会输出本地邮箱记录快照文件路径。看到这些输出后,再回到扩展里点 `校验`、`复制最新验证码`,或开启邮箱记录本地同步。 +同时还会输出本地邮箱记录快照文件路径。看到这些输出后,再回到扩展里点 `校验`、`复制最新验证码`;邮箱记录快照会按默认本地 helper 地址自动同步,无需再手动开启本地同步。 #### 最小排错说明 diff --git a/background.js b/background.js index 1951a63..77b360a 100644 --- a/background.js +++ b/background.js @@ -269,6 +269,7 @@ const PERSISTED_SETTING_DEFAULTS = { autoRunDelayEnabled: false, autoRunDelayMinutes: 30, autoStepDelaySeconds: null, + phoneVerificationEnabled: false, verificationResendCount: DEFAULT_VERIFICATION_RESEND_COUNT, mailProvider: '163', mail2925Mode: DEFAULT_MAIL_2925_MODE, @@ -279,7 +280,7 @@ const PERSISTED_SETTING_DEFAULTS = { autoDeleteUsedIcloudAlias: false, icloudHostPreference: 'auto', icloudFetchMode: 'reuse_existing', - accountRunHistoryTextEnabled: false, + accountRunHistoryTextEnabled: true, accountRunHistoryHelperBaseUrl: DEFAULT_ACCOUNT_RUN_HISTORY_HELPER_BASE_URL, gmailBaseEmail: '', mail2925BaseEmail: '', @@ -969,6 +970,7 @@ function normalizePersistentSettingValue(key, value) { return String(value || ''); case 'autoRunSkipFailures': case 'autoRunDelayEnabled': + case 'phoneVerificationEnabled': return Boolean(value); case 'autoRunFallbackThreadIntervalMinutes': return normalizeAutoRunFallbackThreadIntervalMinutes(value); @@ -7235,12 +7237,14 @@ function isStep6RecoverableResult(result) { } function isAddPhoneAuthUrl(url) { - return /https:\/\/auth\.openai\.com\/add-phone(?:[/?#]|$)/i.test(String(url || '').trim()); + return /https:\/\/auth\.openai\.com\/(?:add-phone|phone-verification)(?:[/?#]|$)/i.test(String(url || '').trim()); } function isAddPhoneAuthState(authState = {}) { return authState?.state === 'add_phone_page' + || authState?.state === 'phone_verification_page' || Boolean(authState?.addPhonePage) + || Boolean(authState?.phoneVerificationPage) || isAddPhoneAuthUrl(authState?.url); } @@ -7532,6 +7536,15 @@ async function waitForStep8Ready(tabId, timeoutMs = STEP8_READY_WAIT_TIMEOUT_MS) throw new Error(`${CLOUDFLARE_SECURITY_BLOCK_ERROR_PREFIX}${CLOUDFLARE_SECURITY_BLOCK_USER_MESSAGE}`); } if (pageState?.addPhonePage || pageState?.phoneVerificationPage) { + const latestState = await getState(); + if (!Boolean(latestState?.phoneVerificationEnabled)) { + const urlPart = pageState?.url ? ` URL: ${pageState.url}` : ''; + throw new Error( + pageState?.phoneVerificationPage + ? `步骤 9:当前认证页进入手机验证码页,但未开启接码功能,无法继续自动授权。${urlPart}`.trim() + : `步骤 9:当前认证页进入手机号页面,但未开启接码功能,无法继续自动授权。${urlPart}`.trim() + ); + } await phoneVerificationHelpers.completePhoneVerificationFlow(tabId, pageState); recovered = false; await sleepWithStop(250); diff --git a/background/account-run-history.js b/background/account-run-history.js index 49b4103..376f0cc 100644 --- a/background/account-run-history.js +++ b/background/account-run-history.js @@ -334,9 +334,6 @@ if (Boolean(state.contributionMode)) { return false; } - if (!Boolean(state.accountRunHistoryTextEnabled)) { - return false; - } const helperBaseUrl = normalizeAccountRunHistoryHelperBaseUrl(state.accountRunHistoryHelperBaseUrl); return Boolean(helperBaseUrl); @@ -364,7 +361,7 @@ body: JSON.stringify(buildAccountRunHistorySnapshotPayload(records)), }); } catch (err) { - throw new Error(`账号记录快照同步失败:无法连接本地 helper(${getErrorMessage(err)})`); + return ''; } let payload = null; diff --git a/background/logging-status.js b/background/logging-status.js index 47692c1..47d3c2c 100644 --- a/background/logging-status.js +++ b/background/logging-status.js @@ -66,7 +66,7 @@ if (/\u624b\u673a\u53f7\u8f93\u5165\u6a21\u5f0f|phone\s+entry/i.test(message)) { return false; } - return /https:\/\/auth\.openai\.com\/add-phone(?:[/?#]|$)|\badd-phone\b|\u6dfb\u52a0\u624b\u673a\u53f7|\u624b\u673a\u53f7\u7801|\u8fdb\u5165\u624b\u673a\u53f7\u9875\u9762|\u624b\u673a\u53f7\u9875|\u624b\u673a\u53f7\u9875\u9762|phone\s+number|telephone/i.test(message); + return /https:\/\/auth\.openai\.com\/(?:add-phone|phone-verification)(?:[/?#]|$)|\badd-phone\b|phone-verification|\u6dfb\u52a0\u624b\u673a\u53f7|\u624b\u673a\u53f7\u7801|\u624b\u673a\u9a8c\u8bc1\u7801\u9875|\u624b\u673a\u9a8c\u8bc1\u9875|\u8fdb\u5165\u624b\u673a\u53f7\u9875\u9762|\u624b\u673a\u53f7\u9875|\u624b\u673a\u53f7\u9875\u9762|phone\s+number|telephone/i.test(message); } function getLoginAuthStateLabel(state) { @@ -84,6 +84,8 @@ return 'OAuth 授权页'; case 'add_phone_page': return '手机号页'; + case 'phone_verification_page': + return '手机验证码页'; default: return '未知页面'; } diff --git a/sidepanel/sidepanel.html b/sidepanel/sidepanel.html index 27c068e..9b76ac1 100644 --- a/sidepanel/sidepanel.html +++ b/sidepanel/sidepanel.html @@ -353,12 +353,12 @@ -
- 本地同步 +
+ 接码
-
-
+ -
+ -
+ diff --git a/sidepanel/sidepanel.js b/sidepanel/sidepanel.js index 9f628bb..192dac1 100644 --- a/sidepanel/sidepanel.js +++ b/sidepanel/sidepanel.js @@ -222,11 +222,14 @@ const inputAutoDelayEnabled = document.getElementById('input-auto-delay-enabled' const inputAutoDelayMinutes = document.getElementById('input-auto-delay-minutes'); const inputAutoStepDelaySeconds = document.getElementById('input-auto-step-delay-seconds'); const inputVerificationResendCount = document.getElementById('input-verification-resend-count'); -const rowAccountRunHistoryTextEnabled = document.getElementById('row-account-run-history-text-enabled'); +const rowPhoneVerificationEnabled = document.getElementById('row-phone-verification-enabled'); +const inputPhoneVerificationEnabled = document.getElementById('input-phone-verification-enabled'); +const rowHeroSmsPlatform = document.getElementById('row-hero-sms-platform'); +const rowHeroSmsCountry = document.getElementById('row-hero-sms-country'); +const rowHeroSmsApiKey = document.getElementById('row-hero-sms-api-key'); const inputHeroSmsApiKey = document.getElementById('input-hero-sms-api-key'); const selectHeroSmsCountry = document.getElementById('select-hero-sms-country'); const displayHeroSmsPlatform = document.getElementById('display-hero-sms-platform'); -const inputAccountRunHistoryTextEnabled = document.getElementById('input-account-run-history-text-enabled'); const rowAccountRunHistoryHelperBaseUrl = document.getElementById('row-account-run-history-helper-base-url'); const inputAccountRunHistoryHelperBaseUrl = document.getElementById('input-account-run-history-helper-base-url'); const autoStartModal = document.getElementById('auto-start-modal'); @@ -280,6 +283,7 @@ const DEFAULT_LUCKMAIL_EMAIL_TYPE = 'ms_graph'; const DISPLAY_TIMEZONE = 'Asia/Shanghai'; const DEFAULT_ACCOUNT_RUN_HISTORY_HELPER_BASE_URL = 'http://127.0.0.1:17373'; const CONTRIBUTION_UPLOAD_URL = 'https://apikey.qzz.io/'; +const DEFAULT_PHONE_VERIFICATION_ENABLED = false; const DEFAULT_HERO_SMS_COUNTRY_ID = 52; const DEFAULT_HERO_SMS_COUNTRY_LABEL = 'Thailand'; @@ -1701,7 +1705,7 @@ function collectSettingsPayload() { ? 'always_new' : 'reuse_existing'), ...(contributionModeEnabled ? {} : { - accountRunHistoryTextEnabled: Boolean(inputAccountRunHistoryTextEnabled?.checked), + accountRunHistoryTextEnabled: true, accountRunHistoryHelperBaseUrl: normalizeAccountRunHistoryHelperBaseUrlValue(inputAccountRunHistoryHelperBaseUrl?.value), }), ...buildManagedAliasBaseEmailPayload(), @@ -1728,6 +1732,7 @@ function collectSettingsPayload() { autoRunDelayEnabled: inputAutoDelayEnabled.checked, autoRunDelayMinutes: normalizeAutoDelayMinutes(inputAutoDelayMinutes.value), autoStepDelaySeconds: normalizeAutoStepDelaySeconds(inputAutoStepDelaySeconds.value), + phoneVerificationEnabled: Boolean(inputPhoneVerificationEnabled?.checked), verificationResendCount: normalizeVerificationResendCount( inputVerificationResendCount?.value, DEFAULT_VERIFICATION_RESEND_COUNT @@ -1897,13 +1902,21 @@ function setHotmailServiceMode(mode) { } function updateAccountRunHistorySettingsUI() { - if (!rowAccountRunHistoryHelperBaseUrl || !inputAccountRunHistoryTextEnabled) { + if (!rowAccountRunHistoryHelperBaseUrl) { return; } - rowAccountRunHistoryHelperBaseUrl.style.display = inputAccountRunHistoryTextEnabled.checked && !latestState?.contributionMode - ? '' - : 'none'; + rowAccountRunHistoryHelperBaseUrl.style.display = 'none'; +} + +function updatePhoneVerificationSettingsUI() { + const enabled = Boolean(inputPhoneVerificationEnabled?.checked); + [rowHeroSmsPlatform, rowHeroSmsCountry, rowHeroSmsApiKey].forEach((row) => { + if (!row) { + return; + } + row.style.display = enabled ? '' : 'none'; + }); } function setSettingsCardLocked(locked) { @@ -2190,9 +2203,6 @@ function applySettingsState(state) { if (checkboxAutoDeleteIcloud) { checkboxAutoDeleteIcloud.checked = Boolean(state?.autoDeleteUsedIcloudAlias); } - if (inputAccountRunHistoryTextEnabled) { - inputAccountRunHistoryTextEnabled.checked = Boolean(state?.accountRunHistoryTextEnabled); - } if (inputAccountRunHistoryHelperBaseUrl) { inputAccountRunHistoryHelperBaseUrl.value = normalizeAccountRunHistoryHelperBaseUrlValue(state?.accountRunHistoryHelperBaseUrl); } @@ -2237,6 +2247,11 @@ function applySettingsState(state) { normalizeVerificationResendCount(restoredVerificationResendCount, DEFAULT_VERIFICATION_RESEND_COUNT) ); } + if (inputPhoneVerificationEnabled) { + inputPhoneVerificationEnabled.checked = state?.phoneVerificationEnabled !== undefined + ? Boolean(state.phoneVerificationEnabled) + : DEFAULT_PHONE_VERIFICATION_ENABLED; + } if (inputHeroSmsApiKey) { inputHeroSmsApiKey.value = state?.heroSmsApiKey || ''; } @@ -2256,6 +2271,7 @@ function applySettingsState(state) { updateAutoDelayInputState(); updateFallbackThreadIntervalInputState(); updateAccountRunHistorySettingsUI(); + updatePhoneVerificationSettingsUI(); updatePanelModeUI(); updateMailProviderUI(); if (isLuckmailProvider(state?.mailProvider)) { @@ -3942,7 +3958,7 @@ const contributionModeManager = window.SidepanelContributionMode?.createContribu contributionModeText, contributionOauthStatus, rowAccountRunHistoryHelperBaseUrl, - rowAccountRunHistoryTextEnabled, + rowPhoneVerificationEnabled, rowCustomPassword, rowLocalCpaStep9Mode, rowSub2ApiDefaultProxy, @@ -5029,8 +5045,8 @@ inputAutoDelayMinutes.addEventListener('blur', () => { saveSettings({ silent: true }).catch(() => { }); }); -inputAccountRunHistoryTextEnabled?.addEventListener('change', () => { - updateAccountRunHistorySettingsUI(); +inputPhoneVerificationEnabled?.addEventListener('change', () => { + updatePhoneVerificationSettingsUI(); markSettingsDirty(true); saveSettings({ silent: true }).catch(() => { }); }); @@ -5279,12 +5295,9 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => { if (message.payload.autoDeleteUsedIcloudAlias !== undefined && checkboxAutoDeleteIcloud) { checkboxAutoDeleteIcloud.checked = Boolean(message.payload.autoDeleteUsedIcloudAlias); } - if (message.payload.accountRunHistoryTextEnabled !== undefined && inputAccountRunHistoryTextEnabled) { - inputAccountRunHistoryTextEnabled.checked = Boolean(message.payload.accountRunHistoryTextEnabled); - updateAccountRunHistorySettingsUI(); - } if (message.payload.accountRunHistoryHelperBaseUrl !== undefined && inputAccountRunHistoryHelperBaseUrl) { inputAccountRunHistoryHelperBaseUrl.value = normalizeAccountRunHistoryHelperBaseUrlValue(message.payload.accountRunHistoryHelperBaseUrl); + updateAccountRunHistorySettingsUI(); } if (message.payload.icloudHostPreference !== undefined && selectIcloudHostPreference) { const hostPreference = String(message.payload.icloudHostPreference || '').trim().toLowerCase(); @@ -5336,6 +5349,10 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => { if (message.payload.heroSmsApiKey !== undefined && inputHeroSmsApiKey) { inputHeroSmsApiKey.value = message.payload.heroSmsApiKey || ''; } + if (message.payload.phoneVerificationEnabled !== undefined && inputPhoneVerificationEnabled) { + inputPhoneVerificationEnabled.checked = Boolean(message.payload.phoneVerificationEnabled); + updatePhoneVerificationSettingsUI(); + } if ( (message.payload.heroSmsCountryId !== undefined || message.payload.heroSmsCountryLabel !== undefined) && selectHeroSmsCountry @@ -5352,6 +5369,7 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => { } updateHeroSmsPlatformDisplay(message.payload.heroSmsCountryLabel || getSelectedHeroSmsCountryOption().label); } + updateAccountRunHistorySettingsUI(); renderContributionMode(); break; } diff --git a/tests/background-account-history-settings.test.js b/tests/background-account-history-settings.test.js index 5a2ebe8..6a8d775 100644 --- a/tests/background-account-history-settings.test.js +++ b/tests/background-account-history-settings.test.js @@ -98,6 +98,7 @@ return { `)(); assert.equal(api.normalizePersistentSettingValue('accountRunHistoryTextEnabled', 1), true); + assert.equal(api.normalizePersistentSettingValue('phoneVerificationEnabled', 1), true); assert.equal(api.normalizePersistentSettingValue('verificationResendCount', '7'), 7); assert.equal(api.normalizePersistentSettingValue('verificationResendCount', '-1'), 0); assert.equal( diff --git a/tests/background-account-run-history-module.test.js b/tests/background-account-run-history-module.test.js index 4345d6a..cdb58da 100644 --- a/tests/background-account-run-history-module.test.js +++ b/tests/background-account-run-history-module.test.js @@ -54,7 +54,7 @@ test('account run history helper upgrades old records, keeps stopped items and s autoRunTotalRuns: 10, autoRunAttemptRun: 3, accountRunHistoryTextEnabled: false, - accountRunHistoryHelperBaseUrl: '', + accountRunHistoryHelperBaseUrl: 'http://127.0.0.1:17373', }), normalizeAccountRunHistoryHelperBaseUrl: (value) => String(value || '').trim(), }); @@ -97,8 +97,8 @@ test('account run history helper upgrades old records, keeps stopped items and s assert.equal(storedHistory.some((item) => item.email === 'stop@example.com' && item.finalStatus === 'stopped'), true); assert.equal(storedHistory.some((item) => item.email === 'latest@example.com' && item.retryCount === 2), true); assert.equal(storedHistory.some((item) => item.email === 'old@example.com'), true); - assert.equal(fetchCalled, false); - assert.equal(helpers.shouldAppendAccountRunTextFile({ accountRunHistoryTextEnabled: false, accountRunHistoryHelperBaseUrl: 'http://127.0.0.1:17373' }), false); + assert.equal(fetchCalled, true); + assert.equal(helpers.shouldAppendAccountRunTextFile({ accountRunHistoryTextEnabled: false, accountRunHistoryHelperBaseUrl: 'http://127.0.0.1:17373' }), true); assert.equal(helpers.shouldAppendAccountRunTextFile({ accountRunHistoryTextEnabled: true, accountRunHistoryHelperBaseUrl: 'http://127.0.0.1:17373' }), true); const stoppedRecord = helpers.buildAccountRunHistoryRecord( { email: 'a@b.com', password: 'x' }, diff --git a/tests/background-logging-status-module.test.js b/tests/background-logging-status-module.test.js index fbff2ff..b5f94f6 100644 --- a/tests/background-logging-status-module.test.js +++ b/tests/background-logging-status-module.test.js @@ -39,4 +39,9 @@ test('logging/status add-phone detection ignores step 2 phone-entry switch failu loggingStatus.isAddPhoneAuthFailure('Step 8: verification submitted but the auth flow entered the phone number page. URL: https://auth.openai.com/add-phone'), true ); + assert.equal( + loggingStatus.isAddPhoneAuthFailure('Step 9: auth page entered phone verification page. URL: https://auth.openai.com/phone-verification'), + true + ); + assert.equal(loggingStatus.getLoginAuthStateLabel('phone_verification_page'), '手机验证码页'); }); diff --git a/tests/sidepanel-contribution-mode.test.js b/tests/sidepanel-contribution-mode.test.js index 73e1c18..dd5fb33 100644 --- a/tests/sidepanel-contribution-mode.test.js +++ b/tests/sidepanel-contribution-mode.test.js @@ -142,6 +142,7 @@ const selectMailProvider = { value: '163' }; const selectEmailGenerator = { value: 'duck' }; const checkboxAutoDeleteIcloud = { checked: true }; const selectIcloudHostPreference = { value: 'auto' }; +const inputPhoneVerificationEnabled = { checked: true }; const inputAccountRunHistoryTextEnabled = { checked: true }; const inputAccountRunHistoryHelperBaseUrl = { value: 'http://127.0.0.1:17373' }; const inputInbucketHost = { value: 'inbucket.local' }; @@ -193,6 +194,7 @@ return { assert.equal('customPassword' in contributionPayload, false); assert.equal('accountRunHistoryTextEnabled' in contributionPayload, false); assert.equal('accountRunHistoryHelperBaseUrl' in contributionPayload, false); + assert.equal(contributionPayload.phoneVerificationEnabled, true); assert.equal(contributionPayload.cloudflareTempEmailUseRandomSubdomain, true); api.setLatestState({ contributionMode: false }); @@ -200,6 +202,7 @@ return { assert.equal(normalPayload.customPassword, 'Secret123!'); assert.equal(normalPayload.accountRunHistoryTextEnabled, true); assert.equal(normalPayload.accountRunHistoryHelperBaseUrl, 'http://127.0.0.1:17373'); + assert.equal(normalPayload.phoneVerificationEnabled, true); assert.equal(normalPayload.codex2apiUrl, 'http://localhost:8080/admin/accounts'); assert.equal(normalPayload.codex2apiAdminKey, 'codex-admin-secret'); assert.equal(normalPayload.cloudflareTempEmailUseRandomSubdomain, true); diff --git a/tests/sidepanel-mail2925-base-email.test.js b/tests/sidepanel-mail2925-base-email.test.js index 03dd79d..492b1a7 100644 --- a/tests/sidepanel-mail2925-base-email.test.js +++ b/tests/sidepanel-mail2925-base-email.test.js @@ -173,6 +173,7 @@ const selectMailProvider = { value: '2925' }; const selectEmailGenerator = { value: 'duck' }; const checkboxAutoDeleteIcloud = { checked: false }; const selectIcloudHostPreference = { value: 'auto' }; +const inputPhoneVerificationEnabled = { checked: false }; const inputAccountRunHistoryTextEnabled = { checked: false }; const inputAccountRunHistoryHelperBaseUrl = { value: '' }; const inputMail2925UseAccountPool = { checked: true }; @@ -227,4 +228,5 @@ return { collectSettingsPayload }; assert.equal(payload.currentMail2925AccountId, 'acc-2'); assert.equal(payload.mail2925UseAccountPool, true); + assert.equal(payload.phoneVerificationEnabled, false); }); diff --git a/tests/sidepanel-phone-verification-settings.test.js b/tests/sidepanel-phone-verification-settings.test.js new file mode 100644 index 0000000..6d66b87 --- /dev/null +++ b/tests/sidepanel-phone-verification-settings.test.js @@ -0,0 +1,181 @@ +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); + +const sidepanelSource = fs.readFileSync('sidepanel/sidepanel.js', 'utf8'); + +function extractFunction(name) { + const markers = [`async function ${name}(`, `function ${name}(`]; + const start = markers + .map((marker) => sidepanelSource.indexOf(marker)) + .find((index) => index >= 0); + if (start < 0) { + throw new Error(`missing function ${name}`); + } + + let parenDepth = 0; + let signatureEnded = false; + let braceStart = -1; + for (let i = start; i < sidepanelSource.length; i += 1) { + const ch = sidepanelSource[i]; + if (ch === '(') { + parenDepth += 1; + } else if (ch === ')') { + parenDepth -= 1; + if (parenDepth === 0) { + signatureEnded = true; + } + } else if (ch === '{' && signatureEnded) { + braceStart = i; + break; + } + } + + let depth = 0; + let end = braceStart; + for (; end < sidepanelSource.length; end += 1) { + const ch = sidepanelSource[end]; + if (ch === '{') depth += 1; + if (ch === '}') { + depth -= 1; + if (depth === 0) { + end += 1; + break; + } + } + } + + return sidepanelSource.slice(start, end); +} + +test('sidepanel html exposes phone verification toggle and dedicated HeroSMS rows', () => { + const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8'); + + assert.match(html, /id="row-phone-verification-enabled"/); + assert.match(html, /id="input-phone-verification-enabled"/); + assert.match(html, /id="row-hero-sms-platform"/); + assert.match(html, /id="row-hero-sms-country"/); + assert.match(html, /id="row-hero-sms-api-key"/); + assert.doesNotMatch(html, /id="input-account-run-history-text-enabled"/); +}); + +test('updatePhoneVerificationSettingsUI toggles HeroSMS rows from the sms switch', () => { + const api = new Function(` +const inputPhoneVerificationEnabled = { checked: false }; +const rowHeroSmsPlatform = { style: { display: 'none' } }; +const rowHeroSmsCountry = { style: { display: 'none' } }; +const rowHeroSmsApiKey = { style: { display: 'none' } }; + +${extractFunction('updatePhoneVerificationSettingsUI')} + +return { + inputPhoneVerificationEnabled, + rowHeroSmsPlatform, + rowHeroSmsCountry, + rowHeroSmsApiKey, + updatePhoneVerificationSettingsUI, +}; +`)(); + + api.updatePhoneVerificationSettingsUI(); + assert.equal(api.rowHeroSmsPlatform.style.display, 'none'); + assert.equal(api.rowHeroSmsCountry.style.display, 'none'); + assert.equal(api.rowHeroSmsApiKey.style.display, 'none'); + + api.inputPhoneVerificationEnabled.checked = true; + api.updatePhoneVerificationSettingsUI(); + assert.equal(api.rowHeroSmsPlatform.style.display, ''); + assert.equal(api.rowHeroSmsCountry.style.display, ''); + assert.equal(api.rowHeroSmsApiKey.style.display, ''); +}); + +test('collectSettingsPayload keeps local helper sync enabled while persisting sms toggle state', () => { + const api = new Function(` +let latestState = { + contributionMode: false, + mail2925UseAccountPool: false, + currentMail2925AccountId: '', +}; +let cloudflareDomainEditMode = false; +let cloudflareTempEmailDomainEditMode = false; +const selectCfDomain = { value: '' }; +const selectTempEmailDomain = { value: '' }; +const selectPanelMode = { value: 'cpa' }; +const inputVpsUrl = { value: '' }; +const inputVpsPassword = { value: '' }; +const inputSub2ApiUrl = { value: '' }; +const inputSub2ApiEmail = { value: '' }; +const inputSub2ApiPassword = { value: '' }; +const inputSub2ApiGroup = { value: '' }; +const inputSub2ApiDefaultProxy = { value: '' }; +const inputCodex2ApiUrl = { value: '' }; +const inputCodex2ApiAdminKey = { value: '' }; +const inputPassword = { value: '' }; +const selectMailProvider = { value: '163' }; +const selectEmailGenerator = { value: 'duck' }; +const checkboxAutoDeleteIcloud = { checked: false }; +const selectIcloudHostPreference = { value: 'auto' }; +const inputMail2925UseAccountPool = { checked: false }; +const inputInbucketHost = { value: '' }; +const inputInbucketMailbox = { value: '' }; +const inputHotmailRemoteBaseUrl = { value: '' }; +const inputHotmailLocalBaseUrl = { value: '' }; +const inputLuckmailApiKey = { value: '' }; +const inputLuckmailBaseUrl = { value: '' }; +const selectLuckmailEmailType = { value: 'ms_graph' }; +const inputLuckmailDomain = { value: '' }; +const inputTempEmailBaseUrl = { value: '' }; +const inputTempEmailAdminAuth = { value: '' }; +const inputTempEmailCustomAuth = { value: '' }; +const inputTempEmailReceiveMailbox = { value: '' }; +const inputTempEmailUseRandomSubdomain = { checked: false }; +const inputAutoSkipFailures = { checked: false }; +const inputAutoSkipFailuresThreadIntervalMinutes = { value: '0' }; +const inputAutoDelayEnabled = { checked: false }; +const inputAutoDelayMinutes = { value: '30' }; +const inputAutoStepDelaySeconds = { value: '' }; +const inputPhoneVerificationEnabled = { checked: true }; +const inputVerificationResendCount = { value: '4' }; +const inputHeroSmsApiKey = { value: 'demo-key' }; +const inputAccountRunHistoryHelperBaseUrl = { value: 'http://127.0.0.1:17373' }; +const DEFAULT_VERIFICATION_RESEND_COUNT = 4; +const DEFAULT_HERO_SMS_COUNTRY_ID = 52; +const DEFAULT_HERO_SMS_COUNTRY_LABEL = 'Thailand'; +const selectHeroSmsCountry = { + value: '52', + selectedIndex: 0, + options: [{ textContent: 'Thailand' }], +}; +function getCloudflareDomainsFromState() { return { domains: [], activeDomain: '' }; } +function normalizeCloudflareDomainValue(value) { return String(value || '').trim(); } +function getCloudflareTempEmailDomainsFromState() { return { domains: [], activeDomain: '' }; } +function normalizeCloudflareTempEmailDomainValue(value) { return String(value || '').trim(); } +function getSelectedLocalCpaStep9Mode() { return 'submit'; } +function getSelectedMail2925Mode() { return 'provide'; } +function getSelectedHotmailServiceMode() { return 'local'; } +function buildManagedAliasBaseEmailPayload() { return { gmailBaseEmail: '', mail2925BaseEmail: '', emailPrefix: '' }; } +function normalizeLuckmailBaseUrl(value) { return String(value || '').trim(); } +function normalizeLuckmailEmailType(value) { return String(value || '').trim() || 'ms_graph'; } +function normalizeCloudflareTempEmailBaseUrlValue(value) { return String(value || '').trim(); } +function normalizeCloudflareTempEmailReceiveMailboxValue(value) { return String(value || '').trim(); } +function normalizeAccountRunHistoryHelperBaseUrlValue(value) { return String(value || '').trim(); } +function normalizeAutoRunThreadIntervalMinutes(value) { return Number(value) || 0; } +function normalizeAutoDelayMinutes(value) { return Number(value) || 30; } +function normalizeAutoStepDelaySeconds(value) { return value === '' ? null : Number(value); } +function normalizeVerificationResendCount(value, fallback) { return Number(value) || fallback; } +${extractFunction('normalizeHeroSmsCountryId')} +${extractFunction('normalizeHeroSmsCountryLabel')} +${extractFunction('getSelectedHeroSmsCountryOption')} +${extractFunction('collectSettingsPayload')} +return { collectSettingsPayload }; +`)(); + + const payload = api.collectSettingsPayload(); + + assert.equal(payload.phoneVerificationEnabled, true); + assert.equal(payload.accountRunHistoryTextEnabled, true); + assert.equal(payload.accountRunHistoryHelperBaseUrl, 'http://127.0.0.1:17373'); + assert.equal(payload.heroSmsApiKey, 'demo-key'); + assert.equal(payload.heroSmsCountryId, 52); + assert.equal(payload.heroSmsCountryLabel, 'Thailand'); +}); diff --git a/tests/step8-retry-page-recovery.test.js b/tests/step8-retry-page-recovery.test.js index c19a75c..564c3de 100644 --- a/tests/step8-retry-page-recovery.test.js +++ b/tests/step8-retry-page-recovery.test.js @@ -140,6 +140,9 @@ const phoneVerificationCalls = []; function throwIfStopped() {} async function sleepWithStop() {} async function ensureStep8SignupPageReady() {} +async function getState() { + return { phoneVerificationEnabled: true }; +} const phoneVerificationHelpers = { async completePhoneVerificationFlow(tabId, pageState) { phoneVerificationCalls.push({ tabId, pageState }); @@ -200,3 +203,52 @@ return { consentReady: true, }); }); + +test('step 8 ready check blocks phone verification flow when sms toggle is disabled', async () => { + const api = new Function(` +const phoneVerificationCalls = []; + +function throwIfStopped() {} +async function sleepWithStop() {} +async function ensureStep8SignupPageReady() {} +async function getState() { + return { phoneVerificationEnabled: false }; +} +const phoneVerificationHelpers = { + async completePhoneVerificationFlow(tabId, pageState) { + phoneVerificationCalls.push({ tabId, pageState }); + return { + success: true, + consentReady: true, + url: 'https://auth.openai.com/authorize', + }; + }, +}; +async function getStep8PageState() { + return { + url: 'https://auth.openai.com/add-phone', + addPhonePage: true, + phoneVerificationPage: false, + consentReady: false, + }; +} + +${extractFunction('waitForStep8Ready')} + +return { + async run() { + try { + await waitForStep8Ready(88, 1000); + return { error: null, phoneVerificationCalls }; + } catch (error) { + return { error, phoneVerificationCalls }; + } + }, +}; +`)(); + + const { error, phoneVerificationCalls } = await api.run(); + + assert.match(String(error?.message || ''), /未开启接码功能/); + assert.deepStrictEqual(phoneVerificationCalls, []); +}); diff --git a/项目完整链路说明.md b/项目完整链路说明.md index 8698aa3..28dd78b 100644 --- a/项目完整链路说明.md +++ b/项目完整链路说明.md @@ -43,7 +43,7 @@ - 在 sidepanel 初始化和点击“自动”按钮前刷新一次贡献站公开内容摘要;如果刷新失败,不阻塞主自动流程 - 在日志区通过“记录”按钮打开独立的邮箱记录覆盖层,并展示成功/失败/停止/重试统计与分页列表 - 查询 GitHub Releases 并展示更新卡片;当前更新服务会区分 `Pro` 与 legacy `v` 两个版本族,排序时优先保持版本族语义一致,同时会在读取缓存后重新排序,避免旧缓存把 `v` 版本误显示为比 `Pro` 更新 -- 展示 HeroSMS 的接码国家与 API Key 设置,用于 OAuth 登录链路命中手机号验证页时直接续跑手机验证 +- 展示一个单独的“接码”开关;开启后才展示 HeroSMS 的接码国家与 API Key 设置,用于 OAuth 登录链路命中手机号验证页时直接续跑手机验证 - 为 Hotmail / 2925 账号池复用同一套“添加账号 / 取消添加 / 批量导入 / 收起列表”表单交互;共享的显隐控制放在 `sidepanel/account-pool-ui.js`,各自 manager 只保留 provider 相关字段校验与业务操作 ### 2.2 Background Service Worker @@ -162,19 +162,19 @@ - 2925 是否启用号池模式 `mail2925UseAccountPool` - 2925 当前选中的号池账号 ID `currentMail2925AccountId` - Cloudflare / Temp Email 设置 -- HeroSMS 的 API Key 与默认国家设置 +- 接码开关,以及 HeroSMS 的 API Key 与默认国家设置 - iCloud 相关偏好 - LuckMail API 配置 - 自动运行默认配置 - 账号运行历史 `accountRunHistory`(以邮箱为主键,保存该邮箱最近一次状态:成功/失败/停止) -- 账号运行历史本地同步开关与 helper 地址 +- 账号运行历史本地同步 helper 地址 注意: - `contributionMode` 不属于持久配置,也不参与导入/导出;它只存在于运行态 - `panelMode` 当前表示 `cpa | sub2api | codex2api` 三个来源;贡献模式仍不是新的来源枚举 -当启用了独立的账号运行历史本地同步配置时,账号运行历史会通过 [scripts/hotmail_helper.py](c:/Users/projectf/Downloads/codex注册扩展/scripts/hotmail_helper.py) 整体同步写入 `data/account-run-history.json` 快照文件,便于开发者直接查看完整记录。 +账号运行历史会默认通过 [scripts/hotmail_helper.py](c:/Users/projectf/Downloads/codex注册扩展/scripts/hotmail_helper.py) 的本地 helper 地址尝试同步写入 `data/account-run-history.json` 快照文件;如果 helper 没有运行,则静默跳过,不再要求用户先手动打开一个“本地同步”开关。 这条配置链路独立于 `mailProvider` 和 Hotmail 的接码模式。 ### 4.3 状态广播 @@ -195,7 +195,7 @@ 1. 用户点击顶部 `贡献` 2. sidepanel 直接通过 `SET_CONTRIBUTION_MODE` 切换运行态,不再弹确认窗口 3. 进入贡献模式后会强制 `panelMode = cpa`,并临时清空运行态 `customPassword`、禁用运行态账号记录快照同步 -4. sidepanel 隐藏 CPA 管理地址、管理密钥、SUB2API 配置、Codex2API 配置、自定义密码、本地同步等普通模式配置,并禁用来源选择、配置菜单和记录入口 +4. sidepanel 隐藏 CPA 管理地址、管理密钥、SUB2API 配置、Codex2API 配置、自定义密码等普通模式配置,并禁用来源选择、配置菜单和记录入口 5. 用户点击 `开始贡献` 后,不再单独走一条旁路 OAuth 流程,而是直接复用顶部 `自动` 的同一套主自动流 6. 步骤 1~6 仍按原来的注册自动化执行 7. 当主流程进入步骤 7 时,后台改为调用公开接口 `POST https://apikey.qzz.io/oauth/api/start` 申请贡献登录地址,而不是去 CPA / SUB2API / Codex2API 来源刷新 OAuth @@ -214,7 +214,7 @@ - 扩展代码中不能直接调用 `/v0/management/*` - 扩展不会直接访问生产管理面或生产 auth-dir - 安全边界仍然在服务端;扩展只负责公开 OAuth 贡献前端流程 -- 退出贡献模式后,要恢复普通模式 UI,并恢复持久配置中的自定义密码/本地同步偏好 +- 退出贡献模式后,要恢复普通模式 UI,并恢复持久配置中的自定义密码等普通模式偏好 ### 4.5 贡献内容更新提示链路 @@ -583,7 +583,7 @@ Codex2API 补充: 补充: - 本地 helper 除了收信与验证码读取,还提供邮箱记录 JSON 快照同步接口。 -- 账号运行历史本地同步由独立配置控制,不再绑定 Hotmail 的本地助手模式。 +- 账号运行历史快照会按默认本地 helper 地址自动尝试同步,不再要求用户手动打开独立开关,也不再绑定 Hotmail 的本地助手模式。 - sidepanel 中 Hotmail 账号池的新增表单默认收起,头部通过共享按钮切换“添加账号 / 取消添加”;表单显隐、按钮文案切换、清空与聚焦都复用 `sidepanel/account-pool-ui.js`,不在 Hotmail manager 内重复实现一套。 ### 7.3 LuckMail diff --git a/项目文件结构说明.md b/项目文件结构说明.md index 6bffabb..017ec79 100644 --- a/项目文件结构说明.md +++ b/项目文件结构说明.md @@ -41,7 +41,7 @@ ## `background/` -- `background/account-run-history.js`:邮箱记录模块,负责以邮箱为主键维护最新记录(同邮箱后续状态覆盖),在步骤 2 设定邮箱后支持先写入“停止/未完成”占位状态,统一归一化成功/失败/停止三态并落地到 `chrome.storage.local`,支持清理记录,并在启用独立本地同步配置后把完整快照同步到本地 helper。 +- `background/account-run-history.js`:邮箱记录模块,负责以邮箱为主键维护最新记录(同邮箱后续状态覆盖),在步骤 2 设定邮箱后支持先写入“停止/未完成”占位状态,统一归一化成功/失败/停止三态并落地到 `chrome.storage.local`,支持清理记录,并按默认本地 helper 地址自动尝试把完整快照同步到本地 helper;若 helper 未启动,则静默跳过。 - `background/auto-run-controller.js`:自动运行主控制器,封装多轮执行、重试、轮次摘要、线程间隔与倒计时恢复逻辑;当前自动流程会绑定 `autoRunSessionId`,手动停止后旧的倒计时计划、旧重试链路和旧恢复入口不会再复活已失效的自动运行;fresh-attempt reset 时会额外保留 `gmailBaseEmail`、`mail2925BaseEmail` 与当前 2925 账号选择,避免自动流程重置后丢失别名基邮箱与 2925 切号上下文。 - `background/contribution-oauth.js`:贡献模式的公开 OAuth 流程模块,负责调用 `apikey.qzz.io` 的公开贡献接口、保存贡献会话运行态、在主 10 步流程里为步骤 7 提供贡献登录地址、在步骤 9/10 衔接 callback 捕获与兼容提交 `/oauth/api/submit-callback`,并把真实服务端状态映射回 sidepanel 运行态。 - `background/generated-email-helpers.js`:生成邮箱辅助层,除了 Duck / Cloudflare / iCloud / Cloudflare Temp Email,也统一承接 Gmail / 2925 的别名邮箱生成入口与自定义邮箱池读取;当 provider 为 2925 且 `mail2925Mode = provide` 时,会先确保当前账号池里已有可用账号,再基于该账号生成别名邮箱;若 `mail2925Mode = receive`,则会回退到普通邮箱生成链路;当生成方式为 iCloud 且 `icloudFetchMode = always_new` 时,会强制跳过未用别名复用并新建别名;当生成方式为 `custom-pool` 时,会按当前目标轮次读取邮箱池中的对应邮箱。 @@ -124,8 +124,8 @@ - `sidepanel/contribution-content-update-service.js`:侧边栏贡献内容更新服务,负责拉取 `https://apikey.qzz.io/api/content-summary`、缓存公开公告/教程摘要,并输出可用于提示展示的 `promptVersion` 与最新更新时间。 - `sidepanel/contribution-mode.js`:侧边栏贡献模式管理器,负责顶部“贡献”按钮、确认弹窗、贡献模式显隐、复用主自动流程启动、侧栏内贡献状态轮询、上传页跳转,以及贡献模式下对来源选择、配置入口、记录入口和敏感配置行(包括 Codex2API 配置)的禁用与隐藏。 - `sidepanel/sidepanel.css`:侧边栏样式文件;当前额外提供 Hotmail / 2925 共用的号池表单容器、操作按钮行与统一的收起态列表高度样式。 -- `sidepanel/sidepanel.html`:侧边栏页面结构;当前步骤列表已改为动态容器,日志区提供“记录”按钮并挂接邮箱记录覆盖层,顶部新增“贡献”按钮并在设置卡片中新增贡献模式主面板;贡献按钮下方额外挂接一个可关闭的轻提示气泡,用于提示公开公告 / 使用教程有更新;贡献面板内展示 `OAUTH / 回调 / 总状态` 三块真实运行态信息,同时把“本地同步”与“验证码重发”拆成独立行以避免特殊模式隐藏时互相影响;页面继续加载 `managed-alias-utils.js`,并把旧的“邮箱前缀”字段语义改为“别名基邮箱”;当 provider 为 2925 时,会额外显示 `提供邮箱 / 接收邮箱` 模式切换,并把“2925 号池”从别名基邮箱行拆成独立配置行,避免 receive 模式把账号池开关一起隐藏;当前在 `邮箱生成` 区域新增 `自定义邮箱池` 选项和多行邮箱池输入框,并在 `邮箱服务 = 自定义邮箱` 时额外显示 `自定义号池` 文本框;来源下拉框当前支持 `CPA / SUB2API / Codex2API`,其中 Codex2API 额外提供后台地址和管理密钥配置行;设置卡片中当前还新增 HeroSMS 的接码平台、国家与 API Key 行,用于 OAuth 链路的手机号验证;Hotmail / 2925 两个账号池当前都使用统一的头部“添加账号/取消添加”按钮和共享表单容器。 -- `sidepanel/sidepanel.js`:侧边栏主入口脚本,负责 UI 状态同步、动态步骤渲染、按钮交互、独立本地同步配置、共享验证码自动重发次数配置与广播接收,并装配 Hotmail / 2925 / iCloud / LuckMail / 贡献模式 / 邮箱记录面板 / 贡献内容更新服务;当前贡献模式的“开始贡献”会直接复用主自动流程启动逻辑,而独立 manager 负责贡献运行态展示与轮询,同时把 Gmail / 2925 的基邮箱输入、完整注册邮箱输入、自动生成按钮与兼容性校验统一接到共享别名逻辑上;当 provider 为 2925 时,会根据 `mail2925Mode` 决定是否启用别名基邮箱链路,而 2925 号池开关与当前账号选择则独立显示并同时服务于 provide / receive 两种模式;`自定义邮箱池` 模式会按邮箱池长度锁定自动轮数,并把当前输入的邮箱池配置参与自动启动前保存;`邮箱服务 = 自定义邮箱` 时,如果配置了 `customMailProviderPool`,也会按号池长度锁定自动轮数并在 Auto 中按轮次分配注册邮箱,同时在普通失败时继续复用当前邮箱,只有成功或出现手机号验证时才切换下一个邮箱;Step 8 的自定义邮箱确认弹窗当前额外提供“出现手机号验证”按钮,用于直接走与真实 add-phone 一致的 fatal 分支;HeroSMS 国家列表会在 sidepanel 初始化时拉取并恢复到本地保存的国家/API 设置;新来源 Codex2API 在这里仅补充来源配置接线、表单显隐和 Step 10 按钮文案,不承接协议业务逻辑;Hotmail / 2925 的新增表单显隐统一接到 `sidepanel/account-pool-ui.js` 这一层共享 helper;侧边栏初始化与点击“自动”前会刷新一次贡献站公开内容摘要,并按本地关闭版本决定是否展示轻提示,同时在首次初始化后按现有规则决定是否弹出新手引导提示。 +- `sidepanel/sidepanel.html`:侧边栏页面结构;当前步骤列表已改为动态容器,日志区提供“记录”按钮并挂接邮箱记录覆盖层,顶部新增“贡献”按钮并在设置卡片中新增贡献模式主面板;贡献按钮下方额外挂接一个可关闭的轻提示气泡,用于提示公开公告 / 使用教程有更新;贡献面板内展示 `OAUTH / 回调 / 总状态` 三块真实运行态信息,同时把“接码”开关与“验证码重发”拆成同一行展示;只有开启接码后,下面的 HeroSMS 平台、国家与 API Key 行才会显示;页面继续加载 `managed-alias-utils.js`,并把旧的“邮箱前缀”字段语义改为“别名基邮箱”;当 provider 为 2925 时,会额外显示 `提供邮箱 / 接收邮箱` 模式切换,并把“2925 号池”从别名基邮箱行拆成独立配置行,避免 receive 模式把账号池开关一起隐藏;当前在 `邮箱生成` 区域新增 `自定义邮箱池` 选项和多行邮箱池输入框,并在 `邮箱服务 = 自定义邮箱` 时额外显示 `自定义号池` 文本框;来源下拉框当前支持 `CPA / SUB2API / Codex2API`,其中 Codex2API 额外提供后台地址和管理密钥配置行;Hotmail / 2925 两个账号池当前都使用统一的头部“添加账号/取消添加”按钮和共享表单容器。 +- `sidepanel/sidepanel.js`:侧边栏主入口脚本,负责 UI 状态同步、动态步骤渲染、按钮交互、共享验证码自动重发次数配置与广播接收,并装配 Hotmail / 2925 / iCloud / LuckMail / 贡献模式 / 邮箱记录面板 / 贡献内容更新服务;当前贡献模式的“开始贡献”会直接复用主自动流程启动逻辑,而独立 manager 负责贡献运行态展示与轮询,同时把 Gmail / 2925 的基邮箱输入、完整注册邮箱输入、自动生成按钮与兼容性校验统一接到共享别名逻辑上;当 provider 为 2925 时,会根据 `mail2925Mode` 决定是否启用别名基邮箱链路,而 2925 号池开关与当前账号选择则独立显示并同时服务于 provide / receive 两种模式;`自定义邮箱池` 模式会按邮箱池长度锁定自动轮数,并把当前输入的邮箱池配置参与自动启动前保存;`邮箱服务 = 自定义邮箱` 时,如果配置了 `customMailProviderPool`,也会按号池长度锁定自动轮数并在 Auto 中按轮次分配注册邮箱,同时在普通失败时继续复用当前邮箱,只有成功或出现手机号验证时才切换下一个邮箱;Step 8 的自定义邮箱确认弹窗当前额外提供“出现手机号验证”按钮,用于直接走与真实 add-phone 一致的 fatal 分支;HeroSMS 国家列表会在 sidepanel 初始化时拉取并恢复到本地保存的国家/API 设置,接码开关关闭时会直接隐藏相关配置;账号记录快照同步改为默认自动模式,只要本地 helper 可用就会自动落盘;新来源 Codex2API 在这里仅补充来源配置接线、表单显隐和 Step 10 按钮文案,不承接协议业务逻辑;Hotmail / 2925 的新增表单显隐统一接到 `sidepanel/account-pool-ui.js` 这一层共享 helper;侧边栏初始化与点击“自动”前会刷新一次贡献站公开内容摘要,并按本地关闭版本决定是否展示轻提示,同时在首次初始化后按现有规则决定是否弹出新手引导提示。 - `sidepanel/update-service.js`:侧边栏更新检查服务,负责 GitHub Releases 查询、`Pro` / `v` 双版本族排序、缓存读取与版本展示。 ## `tests/`