feat: 添加2925邮箱模式选择功能
This commit is contained in:
+31
-6
@@ -43,6 +43,9 @@ const AUTO_STEP_DELAY_MIN_ALLOWED_SECONDS = 0;
|
||||
const AUTO_STEP_DELAY_MAX_ALLOWED_SECONDS = 600;
|
||||
const LEGACY_AUTO_STEP_DELAY_KEYS = ['autoStepRandomDelayMinSeconds', 'autoStepRandomDelayMaxSeconds'];
|
||||
const DEFAULT_LOCAL_CPA_STEP9_MODE = 'submit';
|
||||
const MAIL_2925_MODE_PROVIDE = 'provide';
|
||||
const MAIL_2925_MODE_RECEIVE = 'receive';
|
||||
const DEFAULT_MAIL_2925_MODE = MAIL_2925_MODE_PROVIDE;
|
||||
const HOTMAIL_SERVICE_MODE_REMOTE = 'remote';
|
||||
const HOTMAIL_SERVICE_MODE_LOCAL = 'local';
|
||||
const DEFAULT_HOTMAIL_REMOTE_BASE_URL = '';
|
||||
@@ -72,6 +75,7 @@ const PERSISTED_SETTING_DEFAULTS = {
|
||||
autoRunDelayMinutes: 30,
|
||||
autoStepDelaySeconds: null,
|
||||
mailProvider: '163',
|
||||
mail2925Mode: DEFAULT_MAIL_2925_MODE,
|
||||
emailGenerator: 'duck',
|
||||
emailPrefix: '',
|
||||
inbucketHost: '',
|
||||
@@ -244,6 +248,12 @@ function normalizeMailProvider(value = '') {
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeMail2925Mode(value = '') {
|
||||
return String(value || '').trim().toLowerCase() === MAIL_2925_MODE_RECEIVE
|
||||
? MAIL_2925_MODE_RECEIVE
|
||||
: DEFAULT_MAIL_2925_MODE;
|
||||
}
|
||||
|
||||
function normalizeLocalCpaStep9Mode(value = '') {
|
||||
return String(value || '').trim().toLowerCase() === 'bypass'
|
||||
? 'bypass'
|
||||
@@ -361,6 +371,8 @@ function normalizePersistentSettingValue(key, value) {
|
||||
return normalizeAutoStepDelaySeconds(value, PERSISTED_SETTING_DEFAULTS.autoStepDelaySeconds);
|
||||
case 'mailProvider':
|
||||
return normalizeMailProvider(value);
|
||||
case 'mail2925Mode':
|
||||
return normalizeMail2925Mode(value);
|
||||
case 'emailGenerator':
|
||||
return normalizeEmailGenerator(value);
|
||||
case 'emailPrefix':
|
||||
@@ -653,6 +665,13 @@ function isCustomMailProvider(stateOrProvider) {
|
||||
return provider === 'custom';
|
||||
}
|
||||
|
||||
function getMail2925Mode(stateOrMode) {
|
||||
if (typeof stateOrMode === 'string') {
|
||||
return normalizeMail2925Mode(stateOrMode);
|
||||
}
|
||||
return normalizeMail2925Mode(stateOrMode?.mail2925Mode);
|
||||
}
|
||||
|
||||
async function syncHotmailAccounts(accounts) {
|
||||
const normalized = normalizeHotmailAccounts(accounts);
|
||||
await setPersistentSettings({ hotmailAccounts: normalized });
|
||||
@@ -1276,14 +1295,20 @@ function generateRandomSuffix(length = 6) {
|
||||
return suffix;
|
||||
}
|
||||
|
||||
function isGeneratedAliasProvider(provider) {
|
||||
return provider === '2925';
|
||||
function isGeneratedAliasProvider(stateOrProvider, mail2925Mode = undefined) {
|
||||
const provider = typeof stateOrProvider === 'string'
|
||||
? stateOrProvider
|
||||
: stateOrProvider?.mailProvider;
|
||||
const resolvedMail2925Mode = mail2925Mode !== undefined
|
||||
? normalizeMail2925Mode(mail2925Mode)
|
||||
: getMail2925Mode(stateOrProvider);
|
||||
return provider === '2925' && resolvedMail2925Mode === MAIL_2925_MODE_PROVIDE;
|
||||
}
|
||||
|
||||
function shouldUseCustomRegistrationEmail(state = {}) {
|
||||
return isCustomMailProvider(state)
|
||||
|| (!isHotmailProvider(state)
|
||||
&& !isGeneratedAliasProvider(state.mailProvider)
|
||||
&& !isGeneratedAliasProvider(state)
|
||||
&& normalizeEmailGenerator(state.emailGenerator) === 'custom');
|
||||
}
|
||||
|
||||
@@ -1295,7 +1320,7 @@ function buildGeneratedAliasEmail(state) {
|
||||
throw new Error('2925 邮箱前缀未设置,请先在侧边栏填写。');
|
||||
}
|
||||
|
||||
if (provider === '2925') {
|
||||
if (provider === '2925' && isGeneratedAliasProvider(state)) {
|
||||
return `${emailPrefix}${generateRandomSuffix(6)}@2925.com`;
|
||||
}
|
||||
|
||||
@@ -3564,7 +3589,7 @@ async function ensureAutoEmailReady(targetRun, totalRuns, attemptRuns) {
|
||||
return account.email;
|
||||
}
|
||||
|
||||
if (isGeneratedAliasProvider(currentState.mailProvider)) {
|
||||
if (isGeneratedAliasProvider(currentState)) {
|
||||
if (!currentState.emailPrefix) {
|
||||
throw new Error('2925 邮箱前缀未设置,请先在侧边栏填写。');
|
||||
}
|
||||
@@ -4690,7 +4715,7 @@ async function executeStep3(state) {
|
||||
preferredAccountId: state.currentHotmailAccountId || null,
|
||||
});
|
||||
resolvedEmail = account.email;
|
||||
} else if (isGeneratedAliasProvider(state.mailProvider)) {
|
||||
} else if (isGeneratedAliasProvider(state)) {
|
||||
resolvedEmail = buildGeneratedAliasEmail(state);
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +163,13 @@
|
||||
<button id="btn-mail-login" class="btn btn-outline btn-sm data-inline-btn" type="button" disabled>登录</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="data-row" id="row-mail-2925-mode" style="display:none;">
|
||||
<span class="data-label">2925 模式</span>
|
||||
<div id="mail-2925-mode-group" class="choice-group" role="group" aria-label="2925 邮箱模式">
|
||||
<button type="button" class="choice-btn" data-mail-2925-mode="provide">提供邮箱</button>
|
||||
<button type="button" class="choice-btn" data-mail-2925-mode="receive">接收邮箱</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="data-row" id="row-email-generator">
|
||||
<span class="data-label">邮箱生成</span>
|
||||
<select id="select-email-generator" class="data-select">
|
||||
|
||||
+73
-8
@@ -66,6 +66,8 @@ const rowSub2ApiGroup = document.getElementById('row-sub2api-group');
|
||||
const inputSub2ApiGroup = document.getElementById('input-sub2api-group');
|
||||
const selectMailProvider = document.getElementById('select-mail-provider');
|
||||
const btnMailLogin = document.getElementById('btn-mail-login');
|
||||
const rowMail2925Mode = document.getElementById('row-mail-2925-mode');
|
||||
const mail2925ModeButtons = Array.from(document.querySelectorAll('[data-mail-2925-mode]'));
|
||||
const rowEmailGenerator = document.getElementById('row-email-generator');
|
||||
const selectEmailGenerator = document.getElementById('select-email-generator');
|
||||
const hotmailSection = document.getElementById('hotmail-section');
|
||||
@@ -139,6 +141,9 @@ const AUTO_RUN_MAX_RETRIES_PER_ROUND = 3;
|
||||
const AUTO_STEP_DELAY_MIN_SECONDS = 0;
|
||||
const AUTO_STEP_DELAY_MAX_SECONDS = 600;
|
||||
const DEFAULT_LOCAL_CPA_STEP9_MODE = 'submit';
|
||||
const MAIL_2925_MODE_PROVIDE = 'provide';
|
||||
const MAIL_2925_MODE_RECEIVE = 'receive';
|
||||
const DEFAULT_MAIL_2925_MODE = MAIL_2925_MODE_PROVIDE;
|
||||
const AUTO_SKIP_FAILURES_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-skip-failures-prompt-dismissed';
|
||||
const AUTO_RUN_FALLBACK_RISK_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-run-fallback-risk-prompt-dismissed';
|
||||
const AUTO_RUN_FALLBACK_RISK_WARNING_MIN_RUNS = 15;
|
||||
@@ -226,7 +231,8 @@ const LOG_LEVEL_LABELS = {
|
||||
};
|
||||
|
||||
function usesGeneratedAliasMailProvider(provider) {
|
||||
return provider === '2925';
|
||||
return String(provider || '').trim() === '2925'
|
||||
&& getSelectedMail2925Mode() === MAIL_2925_MODE_PROVIDE;
|
||||
}
|
||||
|
||||
function showToast(message, type = 'error', duration = 4000) {
|
||||
@@ -926,6 +932,7 @@ function collectSettingsPayload() {
|
||||
sub2apiGroupName: inputSub2ApiGroup.value.trim(),
|
||||
customPassword: inputPassword.value,
|
||||
mailProvider: selectMailProvider.value,
|
||||
mail2925Mode: getSelectedMail2925Mode(),
|
||||
emailGenerator: selectEmailGenerator.value,
|
||||
emailPrefix: inputEmailPrefix.value.trim(),
|
||||
inbucketHost: inputInbucketHost.value.trim(),
|
||||
@@ -949,6 +956,12 @@ function normalizeLocalCpaStep9Mode(value = '') {
|
||||
: DEFAULT_LOCAL_CPA_STEP9_MODE;
|
||||
}
|
||||
|
||||
function normalizeMail2925Mode(value = '') {
|
||||
return String(value || '').trim().toLowerCase() === MAIL_2925_MODE_RECEIVE
|
||||
? MAIL_2925_MODE_RECEIVE
|
||||
: DEFAULT_MAIL_2925_MODE;
|
||||
}
|
||||
|
||||
function normalizeHotmailServiceMode(value = '') {
|
||||
return HOTMAIL_SERVICE_MODE_LOCAL;
|
||||
}
|
||||
@@ -967,6 +980,20 @@ function setLocalCpaStep9Mode(mode) {
|
||||
});
|
||||
}
|
||||
|
||||
function getSelectedMail2925Mode() {
|
||||
const activeButton = mail2925ModeButtons.find((button) => button.classList.contains('is-active'));
|
||||
return normalizeMail2925Mode(activeButton?.dataset.mail2925Mode);
|
||||
}
|
||||
|
||||
function setMail2925Mode(mode) {
|
||||
const resolvedMode = normalizeMail2925Mode(mode);
|
||||
mail2925ModeButtons.forEach((button) => {
|
||||
const active = button.dataset.mail2925Mode === resolvedMode;
|
||||
button.classList.toggle('is-active', active);
|
||||
button.setAttribute('aria-pressed', String(active));
|
||||
});
|
||||
}
|
||||
|
||||
function getSelectedHotmailServiceMode() {
|
||||
const activeButton = hotmailServiceModeButtons.find((button) => button.classList.contains('is-active'));
|
||||
return normalizeHotmailServiceMode(activeButton?.dataset.hotmailServiceMode);
|
||||
@@ -1213,6 +1240,7 @@ function applySettingsState(state) {
|
||||
? 'custom'
|
||||
: '163');
|
||||
selectMailProvider.value = restoredMailProvider;
|
||||
setMail2925Mode(state?.mail2925Mode);
|
||||
selectEmailGenerator.value = String(state?.emailGenerator || '').trim().toLowerCase() === 'cloudflare' ? 'cloudflare' : 'duck';
|
||||
inputEmailPrefix.value = state?.emailPrefix || '';
|
||||
inputInbucketHost.value = state?.inbucketHost || '';
|
||||
@@ -1567,9 +1595,13 @@ function isCurrentEmailManagedByHotmail(state = latestState) {
|
||||
return inputEmailValue === hotmailEmail || stateEmailValue === hotmailEmail;
|
||||
}
|
||||
|
||||
function isCurrentEmailManagedByGeneratedAlias(provider = latestState?.mailProvider, state = latestState) {
|
||||
function isCurrentEmailManagedByGeneratedAlias(
|
||||
provider = latestState?.mailProvider,
|
||||
state = latestState,
|
||||
mail2925Mode = latestState?.mail2925Mode
|
||||
) {
|
||||
const normalizedProvider = String(provider || '').trim();
|
||||
if (!usesGeneratedAliasMailProvider(normalizedProvider)) {
|
||||
if (!(normalizedProvider === '2925' && normalizeMail2925Mode(mail2925Mode) === MAIL_2925_MODE_PROVIDE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1803,12 +1835,16 @@ function renderHotmailAccounts() {
|
||||
|
||||
function updateMailProviderUI() {
|
||||
const use2925 = selectMailProvider.value === '2925';
|
||||
const useGeneratedAlias = usesGeneratedAliasMailProvider(selectMailProvider.value);
|
||||
const mail2925Mode = getSelectedMail2925Mode();
|
||||
const useGeneratedAlias = use2925 && mail2925Mode === MAIL_2925_MODE_PROVIDE;
|
||||
const useInbucket = selectMailProvider.value === 'inbucket';
|
||||
const useHotmail = selectMailProvider.value === 'hotmail-api';
|
||||
const useCustomEmail = isCustomMailProvider();
|
||||
const useEmailGenerator = !useHotmail && !useGeneratedAlias && !useCustomEmail;
|
||||
updateMailLoginButtonState();
|
||||
if (rowMail2925Mode) {
|
||||
rowMail2925Mode.style.display = use2925 ? '' : 'none';
|
||||
}
|
||||
rowEmailPrefix.style.display = useGeneratedAlias ? '' : 'none';
|
||||
const hotmailServiceMode = getSelectedHotmailServiceMode();
|
||||
rowInbucketHost.style.display = useInbucket ? '' : 'none';
|
||||
@@ -1846,7 +1882,7 @@ function updateMailProviderUI() {
|
||||
const uiCopy = useCustomEmail ? getCustomMailProviderUiCopy() : getEmailGeneratorUiCopy();
|
||||
inputEmail.placeholder = useHotmail
|
||||
? '由 Hotmail 账号池自动分配'
|
||||
: (use2925 ? '步骤 3 自动生成 2925 邮箱并回填' : uiCopy.placeholder);
|
||||
: (useGeneratedAlias ? '步骤 3 自动生成 2925 邮箱并回填' : uiCopy.placeholder);
|
||||
btnFetchEmail.disabled = useGeneratedAlias || useCustomEmail || isAutoRunLockedPhase();
|
||||
if (!btnFetchEmail.disabled) {
|
||||
btnFetchEmail.textContent = uiCopy.buttonLabel;
|
||||
@@ -3002,14 +3038,18 @@ inputPassword.addEventListener('blur', () => {
|
||||
|
||||
selectMailProvider.addEventListener('change', async () => {
|
||||
const previousProvider = latestState?.mailProvider || '';
|
||||
const previousMail2925Mode = latestState?.mail2925Mode;
|
||||
const nextProvider = selectMailProvider.value;
|
||||
updateMailProviderUI();
|
||||
const leavingHotmail = previousProvider === 'hotmail-api'
|
||||
&& nextProvider !== 'hotmail-api'
|
||||
&& isCurrentEmailManagedByHotmail();
|
||||
const leavingGeneratedAlias = previousProvider !== nextProvider
|
||||
&& usesGeneratedAliasMailProvider(previousProvider)
|
||||
&& isCurrentEmailManagedByGeneratedAlias(previousProvider);
|
||||
const leavingGeneratedAlias = (
|
||||
previousProvider !== nextProvider
|
||||
|| (previousProvider === '2925' && normalizeMail2925Mode(previousMail2925Mode) !== getSelectedMail2925Mode())
|
||||
) && previousProvider === '2925'
|
||||
&& normalizeMail2925Mode(previousMail2925Mode) === MAIL_2925_MODE_PROVIDE
|
||||
&& isCurrentEmailManagedByGeneratedAlias(previousProvider, latestState, previousMail2925Mode);
|
||||
if (leavingHotmail || leavingGeneratedAlias) {
|
||||
await clearRegistrationEmail({ silent: true }).catch(() => { });
|
||||
}
|
||||
@@ -3017,6 +3057,30 @@ selectMailProvider.addEventListener('change', async () => {
|
||||
saveSettings({ silent: true }).catch(() => { });
|
||||
});
|
||||
|
||||
mail2925ModeButtons.forEach((button) => {
|
||||
button.addEventListener('click', async () => {
|
||||
const nextMode = normalizeMail2925Mode(button.dataset.mail2925Mode);
|
||||
const previousMode = normalizeMail2925Mode(latestState?.mail2925Mode);
|
||||
if (nextMode === getSelectedMail2925Mode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setMail2925Mode(nextMode);
|
||||
updateMailProviderUI();
|
||||
|
||||
const leavingGeneratedAlias = selectMailProvider.value === '2925'
|
||||
&& previousMode === MAIL_2925_MODE_PROVIDE
|
||||
&& nextMode !== MAIL_2925_MODE_PROVIDE
|
||||
&& isCurrentEmailManagedByGeneratedAlias('2925', latestState, previousMode);
|
||||
if (leavingGeneratedAlias) {
|
||||
await clearRegistrationEmail({ silent: true }).catch(() => { });
|
||||
}
|
||||
|
||||
markSettingsDirty(true);
|
||||
saveSettings({ silent: true }).catch(() => { });
|
||||
});
|
||||
});
|
||||
|
||||
selectEmailGenerator.addEventListener('change', () => {
|
||||
updateMailProviderUI();
|
||||
clearRegistrationEmail({ silent: true }).catch(() => { });
|
||||
@@ -3402,6 +3466,7 @@ initHotmailListExpandedState();
|
||||
updateSaveButtonState();
|
||||
updateConfigMenuControls();
|
||||
setLocalCpaStep9Mode(DEFAULT_LOCAL_CPA_STEP9_MODE);
|
||||
setMail2925Mode(DEFAULT_MAIL_2925_MODE);
|
||||
initializeReleaseInfo().catch((err) => {
|
||||
console.error('Failed to initialize release info:', err);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user