feat: add phone verification flow support

This commit is contained in:
sh2001sh
2026-04-20 17:39:01 +08:00
parent d85f7feaef
commit b098726a6f
13 changed files with 2001 additions and 21 deletions
+14
View File
@@ -362,6 +362,20 @@
<span class="data-label">同步服务</span>
<input type="text" id="input-account-run-history-helper-base-url" class="data-input mono" placeholder="http://127.0.0.1:17373" />
</div>
<div class="data-row">
<span class="data-label">接码平台</span>
<span id="display-hero-sms-platform" class="data-value mono">HeroSMS / OpenAI / Thailand</span>
</div>
<div class="data-row">
<span class="data-label">接码国家</span>
<select id="select-hero-sms-country" class="data-input mono">
<option value="52" selected>Thailand</option>
</select>
</div>
<div class="data-row">
<span class="data-label">接码 API</span>
<input type="password" id="input-hero-sms-api-key" class="data-input mono" placeholder="请输入 HeroSMS API Key" />
</div>
<div class="data-row">
<span class="data-label">OAuth</span>
<span id="display-oauth-url" class="data-value mono truncate">等待中...</span>
+134 -2
View File
@@ -201,6 +201,9 @@ 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 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');
@@ -251,6 +254,9 @@ const DEFAULT_LUCKMAIL_BASE_URL = 'https://mails.luckyous.com';
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_HERO_SMS_COUNTRY_ID = 52;
const DEFAULT_HERO_SMS_COUNTRY_LABEL = 'Thailand';
function getManagedAliasUtils() {
return window.MultiPageManagedAliasUtils || null;
@@ -1431,6 +1437,15 @@ function collectSettingsPayload() {
const mail2925UseAccountPool = typeof inputMail2925UseAccountPool !== 'undefined'
? Boolean(inputMail2925UseAccountPool?.checked)
: Boolean(latestState?.mail2925UseAccountPool);
const heroSmsApiKeyValue = typeof inputHeroSmsApiKey !== 'undefined' && inputHeroSmsApiKey
? (inputHeroSmsApiKey.value || '')
: '';
const heroSmsCountry = typeof getSelectedHeroSmsCountryOption === 'function'
? getSelectedHeroSmsCountryOption()
: {
id: typeof DEFAULT_HERO_SMS_COUNTRY_ID !== 'undefined' ? DEFAULT_HERO_SMS_COUNTRY_ID : 52,
label: typeof DEFAULT_HERO_SMS_COUNTRY_LABEL !== 'undefined' ? DEFAULT_HERO_SMS_COUNTRY_LABEL : 'Thailand',
};
return {
panelMode: selectPanelMode.value,
vpsUrl: inputVpsUrl.value.trim(),
@@ -1481,6 +1496,9 @@ function collectSettingsPayload() {
inputVerificationResendCount?.value,
DEFAULT_VERIFICATION_RESEND_COUNT
),
heroSmsApiKey: heroSmsApiKeyValue,
heroSmsCountryId: heroSmsCountry.id,
heroSmsCountryLabel: heroSmsCountry.label,
};
}
@@ -1529,6 +1547,75 @@ function normalizeAccountRunHistoryHelperBaseUrlValue(value = '') {
}
}
function normalizeHeroSmsCountryId(value) {
return Math.max(1, Math.floor(Number(value) || DEFAULT_HERO_SMS_COUNTRY_ID));
}
function normalizeHeroSmsCountryLabel(value = '') {
return String(value || '').trim() || DEFAULT_HERO_SMS_COUNTRY_LABEL;
}
function getSelectedHeroSmsCountryOption() {
if (!selectHeroSmsCountry) {
return {
id: DEFAULT_HERO_SMS_COUNTRY_ID,
label: DEFAULT_HERO_SMS_COUNTRY_LABEL,
};
}
const option = selectHeroSmsCountry.options[selectHeroSmsCountry.selectedIndex];
return {
id: normalizeHeroSmsCountryId(selectHeroSmsCountry.value),
label: normalizeHeroSmsCountryLabel(option?.textContent),
};
}
function updateHeroSmsPlatformDisplay(label = '') {
if (!displayHeroSmsPlatform) {
return;
}
const countryLabel = normalizeHeroSmsCountryLabel(label);
displayHeroSmsPlatform.textContent = `HeroSMS / OpenAI / ${countryLabel}`;
}
async function loadHeroSmsCountries() {
if (!selectHeroSmsCountry) {
return;
}
const previousValue = selectHeroSmsCountry.value || String(DEFAULT_HERO_SMS_COUNTRY_ID);
try {
const response = await fetch('https://hero-sms.com/stubs/handler_api.php?action=getCountries');
const payload = await response.json();
const countries = Array.isArray(payload?.value) ? payload.value : (Array.isArray(payload) ? payload : []);
if (!countries.length) {
throw new Error('empty country list');
}
const optionsHtml = countries
.filter((item) => Number(item?.id) > 0 && String(item?.eng || '').trim())
.sort((left, right) => String(left.eng || '').localeCompare(String(right.eng || '')))
.map((item) => {
const id = normalizeHeroSmsCountryId(item.id);
const label = String(item.eng || '').trim();
return `<option value="${id}">${label}</option>`;
})
.join('');
if (optionsHtml) {
selectHeroSmsCountry.innerHTML = optionsHtml;
}
} catch (error) {
console.warn('Failed to load HeroSMS countries:', error);
selectHeroSmsCountry.innerHTML = `<option value="${DEFAULT_HERO_SMS_COUNTRY_ID}">${DEFAULT_HERO_SMS_COUNTRY_LABEL}</option>`;
}
selectHeroSmsCountry.value = Array.from(selectHeroSmsCountry.options).some((option) => option.value === previousValue)
? previousValue
: String(DEFAULT_HERO_SMS_COUNTRY_ID);
updateHeroSmsPlatformDisplay(getSelectedHeroSmsCountryOption().label);
}
function getSelectedLocalCpaStep9Mode() {
const activeButton = localCpaStep9ModeButtons.find((button) => button.classList.contains('is-active'));
return normalizeLocalCpaStep9Mode(activeButton?.dataset.localCpaStep9Mode);
@@ -1895,6 +1982,16 @@ function applySettingsState(state) {
normalizeVerificationResendCount(restoredVerificationResendCount, DEFAULT_VERIFICATION_RESEND_COUNT)
);
}
if (inputHeroSmsApiKey) {
inputHeroSmsApiKey.value = state?.heroSmsApiKey || '';
}
if (selectHeroSmsCountry) {
const restoredCountryId = String(normalizeHeroSmsCountryId(state?.heroSmsCountryId));
if (Array.from(selectHeroSmsCountry.options).some((option) => option.value === restoredCountryId)) {
selectHeroSmsCountry.value = restoredCountryId;
}
updateHeroSmsPlatformDisplay(state?.heroSmsCountryLabel || getSelectedHeroSmsCountryOption().label);
}
if (state?.autoRunTotalRuns) {
inputRunCount.value = String(state.autoRunTotalRuns);
}
@@ -4311,6 +4408,20 @@ inputVerificationResendCount?.addEventListener('blur', () => {
saveSettings({ silent: true }).catch(() => { });
});
inputHeroSmsApiKey?.addEventListener('input', () => {
markSettingsDirty(true);
scheduleSettingsAutoSave();
});
inputHeroSmsApiKey?.addEventListener('blur', () => {
saveSettings({ silent: true }).catch(() => { });
});
selectHeroSmsCountry?.addEventListener('change', () => {
updateHeroSmsPlatformDisplay(getSelectedHeroSmsCountryOption().label);
markSettingsDirty(true);
saveSettings({ silent: true }).catch(() => { });
});
// ============================================================
// Listen for Background broadcasts
// ============================================================
@@ -4552,6 +4663,25 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
)
);
}
if (message.payload.heroSmsApiKey !== undefined && inputHeroSmsApiKey) {
inputHeroSmsApiKey.value = message.payload.heroSmsApiKey || '';
}
if (
(message.payload.heroSmsCountryId !== undefined || message.payload.heroSmsCountryLabel !== undefined)
&& selectHeroSmsCountry
) {
const nextCountryId = String(
normalizeHeroSmsCountryId(
message.payload.heroSmsCountryId !== undefined
? message.payload.heroSmsCountryId
: selectHeroSmsCountry.value
)
);
if (Array.from(selectHeroSmsCountry.options).some((option) => option.value === nextCountryId)) {
selectHeroSmsCountry.value = nextCountryId;
}
updateHeroSmsPlatformDisplay(message.payload.heroSmsCountryLabel || getSelectedHeroSmsCountryOption().label);
}
renderContributionMode();
break;
}
@@ -4647,11 +4777,13 @@ setMail2925Mode(DEFAULT_MAIL_2925_MODE);
initializeReleaseInfo().catch((err) => {
console.error('Failed to initialize release info:', err);
});
restoreState().then(() => {
loadHeroSmsCountries().catch((err) => {
console.error('Failed to load HeroSMS countries:', err);
}).finally(() => restoreState().then(() => {
syncPasswordToggleLabel();
syncVpsUrlToggleLabel();
syncVpsPasswordToggleLabel();
updatePanelModeUI();
updateButtonStates();
updateStatusDisplay(latestState);
});
}));