2925邮箱增加账号池功能
This commit is contained in:
+218
-1
@@ -110,6 +110,7 @@ const selectTempEmailDomain = document.getElementById('select-temp-email-domain'
|
||||
const inputTempEmailDomain = document.getElementById('input-temp-email-domain');
|
||||
const btnTempEmailDomainMode = document.getElementById('btn-temp-email-domain-mode');
|
||||
const hotmailSection = document.getElementById('hotmail-section');
|
||||
const mail2925Section = document.getElementById('mail2925-section');
|
||||
const luckmailSection = document.getElementById('luckmail-section');
|
||||
const icloudSection = document.getElementById('icloud-section');
|
||||
const icloudSummary = document.getElementById('icloud-summary');
|
||||
@@ -150,6 +151,15 @@ const btnDeleteAllHotmailAccounts = document.getElementById('btn-delete-all-hotm
|
||||
const btnToggleHotmailList = document.getElementById('btn-toggle-hotmail-list');
|
||||
const hotmailListShell = document.getElementById('hotmail-list-shell');
|
||||
const hotmailAccountsList = document.getElementById('hotmail-accounts-list');
|
||||
const inputMail2925Email = document.getElementById('input-mail2925-email');
|
||||
const inputMail2925Password = document.getElementById('input-mail2925-password');
|
||||
const inputMail2925Import = document.getElementById('input-mail2925-import');
|
||||
const btnAddMail2925Account = document.getElementById('btn-add-mail2925-account');
|
||||
const btnImportMail2925Accounts = document.getElementById('btn-import-mail2925-accounts');
|
||||
const btnDeleteAllMail2925Accounts = document.getElementById('btn-delete-all-mail2925-accounts');
|
||||
const btnToggleMail2925List = document.getElementById('btn-toggle-mail2925-list');
|
||||
const mail2925ListShell = document.getElementById('mail2925-list-shell');
|
||||
const mail2925AccountsList = document.getElementById('mail2925-accounts-list');
|
||||
const inputLuckmailApiKey = document.getElementById('input-luckmail-api-key');
|
||||
const inputLuckmailBaseUrl = document.getElementById('input-luckmail-base-url');
|
||||
const selectLuckmailEmailType = document.getElementById('select-luckmail-email-type');
|
||||
@@ -171,6 +181,9 @@ const luckmailList = document.getElementById('luckmail-list');
|
||||
const rowEmailPrefix = document.getElementById('row-email-prefix');
|
||||
const labelEmailPrefix = document.getElementById('label-email-prefix');
|
||||
const inputEmailPrefix = document.getElementById('input-email-prefix');
|
||||
const selectMail2925PoolAccount = document.getElementById('select-mail2925-pool-account');
|
||||
const inputMail2925UseAccountPool = document.getElementById('input-mail2925-use-account-pool');
|
||||
const labelMail2925UseAccountPool = document.getElementById('label-mail2925-use-account-pool');
|
||||
const rowInbucketHost = document.getElementById('row-inbucket-host');
|
||||
const inputInbucketHost = document.getElementById('input-inbucket-host');
|
||||
const rowInbucketMailbox = document.getElementById('row-inbucket-mailbox');
|
||||
@@ -307,7 +320,70 @@ function getManagedAliasBaseEmailKey(provider = selectMailProvider.value) {
|
||||
return '';
|
||||
}
|
||||
|
||||
function isMail2925AccountPoolEnabled(state = latestState) {
|
||||
return Boolean(state?.mail2925UseAccountPool);
|
||||
}
|
||||
|
||||
function getPreferredMail2925PoolAccountId(state = latestState) {
|
||||
const currentId = String(state?.currentMail2925AccountId || '').trim();
|
||||
if (currentId && getMail2925Accounts(state).some((account) => account.id === currentId)) {
|
||||
return currentId;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function syncMail2925PoolAccountOptions(state = latestState) {
|
||||
if (!selectMail2925PoolAccount) {
|
||||
return;
|
||||
}
|
||||
|
||||
const accounts = getMail2925Accounts(state);
|
||||
const selectedId = getPreferredMail2925PoolAccountId(state);
|
||||
const options = ['<option value="">请选择号池邮箱</option>'].concat(
|
||||
accounts.map((account) => `<option value="${escapeHtml(account.id)}">${escapeHtml(account.email || '(未命名账号)')}</option>`)
|
||||
);
|
||||
selectMail2925PoolAccount.innerHTML = options.join('');
|
||||
selectMail2925PoolAccount.value = selectedId;
|
||||
}
|
||||
|
||||
async function syncSelectedMail2925PoolAccount(options = {}) {
|
||||
const { silent = false } = options;
|
||||
if (!selectMail2925PoolAccount || !isMail2925AccountPoolEnabled(latestState)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const accountId = String(selectMail2925PoolAccount.value || '').trim();
|
||||
if (!accountId) {
|
||||
syncLatestState({ currentMail2925AccountId: null });
|
||||
setManagedAliasBaseEmailInputForProvider('2925', latestState);
|
||||
return null;
|
||||
}
|
||||
|
||||
const response = await chrome.runtime.sendMessage({
|
||||
type: 'SELECT_MAIL2925_ACCOUNT',
|
||||
source: 'sidepanel',
|
||||
payload: { accountId },
|
||||
});
|
||||
if (response?.error) {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
|
||||
syncLatestState({ currentMail2925AccountId: response.account?.id || accountId });
|
||||
setManagedAliasBaseEmailInputForProvider('2925', latestState);
|
||||
if (!silent) {
|
||||
showToast(`已切换当前 2925 号池邮箱为 ${response.account?.email || accountId}`, 'success', 1800);
|
||||
}
|
||||
return response.account || null;
|
||||
}
|
||||
|
||||
function getManagedAliasBaseEmailForProvider(provider = selectMailProvider.value, state = latestState) {
|
||||
if (String(provider || '').trim().toLowerCase() === '2925' && isMail2925AccountPoolEnabled(state)) {
|
||||
const currentMail2925Email = getCurrentMail2925Email(state);
|
||||
if (currentMail2925Email) {
|
||||
return currentMail2925Email;
|
||||
}
|
||||
}
|
||||
|
||||
const key = getManagedAliasBaseEmailKey(provider);
|
||||
if (!key) {
|
||||
return '';
|
||||
@@ -326,11 +402,16 @@ function buildManagedAliasBaseEmailPayload(state = latestState) {
|
||||
const payload = {
|
||||
gmailBaseEmail: String(state?.gmailBaseEmail || '').trim(),
|
||||
mail2925BaseEmail: String(state?.mail2925BaseEmail || '').trim(),
|
||||
mail2925UseAccountPool: Boolean(state?.mail2925UseAccountPool),
|
||||
emailPrefix: '',
|
||||
};
|
||||
const key = getManagedAliasBaseEmailKey();
|
||||
if (key) {
|
||||
payload[key] = inputEmailPrefix.value.trim();
|
||||
if (key === 'mail2925BaseEmail' && isMail2925AccountPoolEnabled(state)) {
|
||||
payload[key] = String(state?.mail2925BaseEmail || '').trim();
|
||||
} else {
|
||||
payload[key] = inputEmailPrefix.value.trim();
|
||||
}
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
@@ -340,10 +421,14 @@ function syncManagedAliasBaseEmailDraftFromInput(provider = selectMailProvider.v
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
if (key === 'mail2925BaseEmail' && isMail2925AccountPoolEnabled(latestState)) {
|
||||
return;
|
||||
}
|
||||
syncLatestState({ [key]: inputEmailPrefix.value.trim() });
|
||||
}
|
||||
|
||||
function setManagedAliasBaseEmailInputForProvider(provider = selectMailProvider.value, state = latestState) {
|
||||
syncMail2925PoolAccountOptions(state);
|
||||
inputEmailPrefix.value = getManagedAliasBaseEmailForProvider(provider, state);
|
||||
}
|
||||
|
||||
@@ -1342,6 +1427,9 @@ function collectSettingsPayload() {
|
||||
!cloudflareTempEmailDomainEditMode ? selectTempEmailDomain.value : tempEmailActiveDomain
|
||||
) || tempEmailActiveDomain;
|
||||
const contributionModeEnabled = Boolean(latestState?.contributionMode);
|
||||
const mail2925UseAccountPool = typeof inputMail2925UseAccountPool !== 'undefined'
|
||||
? Boolean(inputMail2925UseAccountPool?.checked)
|
||||
: Boolean(latestState?.mail2925UseAccountPool);
|
||||
return {
|
||||
panelMode: selectPanelMode.value,
|
||||
vpsUrl: inputVpsUrl.value.trim(),
|
||||
@@ -1357,6 +1445,7 @@ function collectSettingsPayload() {
|
||||
}),
|
||||
mailProvider: selectMailProvider.value,
|
||||
mail2925Mode: getSelectedMail2925Mode(),
|
||||
mail2925UseAccountPool,
|
||||
emailGenerator: selectEmailGenerator.value,
|
||||
autoDeleteUsedIcloudAlias: checkboxAutoDeleteIcloud?.checked,
|
||||
icloudHostPreference: selectIcloudHostPreference?.value || 'auto',
|
||||
@@ -1771,6 +1860,9 @@ function applySettingsState(state) {
|
||||
if (inputContributionQq) {
|
||||
inputContributionQq.value = state?.contributionQq || '';
|
||||
}
|
||||
if (inputMail2925UseAccountPool) {
|
||||
inputMail2925UseAccountPool.checked = Boolean(state?.mail2925UseAccountPool);
|
||||
}
|
||||
setManagedAliasBaseEmailInputForProvider(restoredMailProvider, state);
|
||||
inputInbucketHost.value = state?.inbucketHost || '';
|
||||
inputInbucketMailbox.value = state?.inbucketMailbox || '';
|
||||
@@ -2226,6 +2318,19 @@ function getCurrentHotmailEmail(state = latestState) {
|
||||
return String(getCurrentHotmailAccount(state)?.email || '').trim();
|
||||
}
|
||||
|
||||
function getMail2925Accounts(state = latestState) {
|
||||
return Array.isArray(state?.mail2925Accounts) ? state.mail2925Accounts : [];
|
||||
}
|
||||
|
||||
function getCurrentMail2925Account(state = latestState) {
|
||||
const currentId = state?.currentMail2925AccountId;
|
||||
return getMail2925Accounts(state).find((account) => account.id === currentId) || null;
|
||||
}
|
||||
|
||||
function getCurrentMail2925Email(state = latestState) {
|
||||
return String(getCurrentMail2925Account(state)?.email || '').trim();
|
||||
}
|
||||
|
||||
function getCurrentLuckmailPurchase(state = latestState) {
|
||||
return state?.currentLuckmailPurchase || null;
|
||||
}
|
||||
@@ -2365,6 +2470,8 @@ function updateMailLoginButtonState() {
|
||||
function updateMailProviderUI() {
|
||||
const use2925 = selectMailProvider.value === '2925';
|
||||
const useGmail = selectMailProvider.value === GMAIL_PROVIDER;
|
||||
const useMail2925 = selectMailProvider.value === '2925';
|
||||
const useMail2925AccountPool = useMail2925 && Boolean(inputMail2925UseAccountPool?.checked);
|
||||
const mail2925Mode = getSelectedMail2925Mode();
|
||||
const useGeneratedAlias = usesGeneratedAliasMailProvider(selectMailProvider.value, mail2925Mode);
|
||||
const useInbucket = selectMailProvider.value === 'inbucket';
|
||||
@@ -2427,11 +2534,24 @@ function updateMailProviderUI() {
|
||||
if (hotmailSection) {
|
||||
hotmailSection.style.display = useHotmail ? '' : 'none';
|
||||
}
|
||||
if (mail2925Section) {
|
||||
mail2925Section.style.display = useMail2925AccountPool ? '' : 'none';
|
||||
}
|
||||
if (luckmailSection) {
|
||||
luckmailSection.style.display = useLuckmail ? '' : 'none';
|
||||
}
|
||||
labelEmailPrefix.textContent = '邮箱前缀';
|
||||
inputEmailPrefix.placeholder = '例如 abc';
|
||||
if (labelMail2925UseAccountPool) {
|
||||
labelMail2925UseAccountPool.style.display = useMail2925 ? '' : 'none';
|
||||
}
|
||||
syncMail2925PoolAccountOptions(latestState);
|
||||
if (selectMail2925PoolAccount) {
|
||||
selectMail2925PoolAccount.style.display = useMail2925AccountPool ? '' : 'none';
|
||||
selectMail2925PoolAccount.disabled = !useMail2925AccountPool || getMail2925Accounts().length === 0;
|
||||
}
|
||||
inputEmailPrefix.style.display = useMail2925AccountPool ? 'none' : '';
|
||||
inputEmailPrefix.readOnly = useMail2925AccountPool;
|
||||
selectEmailGenerator.disabled = useHotmail || useLuckmail || useGeneratedAlias || useCustomEmail;
|
||||
if (useGmail) {
|
||||
labelEmailPrefix.textContent = 'Gmail 原邮箱';
|
||||
@@ -2480,6 +2600,11 @@ function updateMailProviderUI() {
|
||||
if (autoHintText && useGeneratedAlias && aliasUiCopy?.hint) {
|
||||
autoHintText.textContent = aliasUiCopy.hint;
|
||||
}
|
||||
if (autoHintText && useMail2925AccountPool) {
|
||||
autoHintText.textContent = getMail2925Accounts().length
|
||||
? '当前已启用 2925 号池模式,步骤 3 会基于下拉框选中的号池邮箱生成别名地址'
|
||||
: '当前已启用 2925 号池模式,请先在下方 2925 账号池中添加账号并选择邮箱';
|
||||
}
|
||||
if (autoHintText && showCloudflareTempEmailReceiveMailbox) {
|
||||
autoHintText.textContent = '若注册邮箱会转发到 Cloudflare Temp Email,请在“邮件接收”中填写实际接收转发邮件的邮箱。';
|
||||
}
|
||||
@@ -2489,6 +2614,9 @@ function updateMailProviderUI() {
|
||||
inputEmail.value = getCurrentLuckmailEmail();
|
||||
}
|
||||
renderHotmailAccounts();
|
||||
if (useMail2925) {
|
||||
renderMail2925Accounts();
|
||||
}
|
||||
if (useLuckmail) {
|
||||
renderLuckmailPurchases();
|
||||
}
|
||||
@@ -2905,6 +3033,50 @@ const bindHotmailEvents = hotmailManager?.bindHotmailEvents
|
||||
|| (() => { });
|
||||
bindHotmailEvents();
|
||||
|
||||
const mail2925Manager = window.SidepanelMail2925Manager?.createMail2925Manager({
|
||||
state: {
|
||||
getLatestState: () => latestState,
|
||||
syncLatestState,
|
||||
},
|
||||
dom: {
|
||||
btnAddMail2925Account,
|
||||
btnDeleteAllMail2925Accounts,
|
||||
btnImportMail2925Accounts,
|
||||
btnToggleMail2925List,
|
||||
inputMail2925Email,
|
||||
inputMail2925Import,
|
||||
inputMail2925Password,
|
||||
mail2925AccountsList,
|
||||
mail2925ListShell,
|
||||
},
|
||||
helpers: {
|
||||
copyTextToClipboard,
|
||||
escapeHtml,
|
||||
getMail2925Accounts,
|
||||
openConfirmModal,
|
||||
refreshManagedAliasBaseEmail: () => {
|
||||
setManagedAliasBaseEmailInputForProvider('2925', latestState);
|
||||
},
|
||||
showToast,
|
||||
},
|
||||
runtime: {
|
||||
sendMessage: (message) => chrome.runtime.sendMessage(message),
|
||||
},
|
||||
constants: {
|
||||
copyIcon: COPY_ICON,
|
||||
displayTimeZone: DISPLAY_TIMEZONE,
|
||||
expandedStorageKey: 'multipage-mail2925-list-expanded',
|
||||
},
|
||||
mail2925Utils: window.Mail2925Utils || {},
|
||||
});
|
||||
const initMail2925ListExpandedState = mail2925Manager?.initMail2925ListExpandedState
|
||||
|| (() => { });
|
||||
const renderMail2925Accounts = mail2925Manager?.renderMail2925Accounts
|
||||
|| (() => { });
|
||||
const bindMail2925Events = mail2925Manager?.bindMail2925Events
|
||||
|| (() => { });
|
||||
bindMail2925Events();
|
||||
|
||||
const icloudManager = window.SidepanelIcloudManager?.createIcloudManager({
|
||||
dom: {
|
||||
btnIcloudBulkDelete,
|
||||
@@ -3775,6 +3947,13 @@ selectMailProvider.addEventListener('change', async () => {
|
||||
if (leavingHotmail || leavingLuckmail || leavingGeneratedAlias) {
|
||||
await clearRegistrationEmail({ silent: true }).catch(() => { });
|
||||
}
|
||||
if (nextProvider === '2925' && Boolean(inputMail2925UseAccountPool?.checked)) {
|
||||
syncMail2925PoolAccountOptions(latestState);
|
||||
if (!selectMail2925PoolAccount.value && getMail2925Accounts().length > 0) {
|
||||
selectMail2925PoolAccount.value = String(getMail2925Accounts()[0]?.id || '');
|
||||
}
|
||||
await syncSelectedMail2925PoolAccount({ silent: true }).catch(() => { });
|
||||
}
|
||||
if (nextProvider === LUCKMAIL_PROVIDER) {
|
||||
queueLuckmailPurchaseRefresh();
|
||||
}
|
||||
@@ -3956,6 +4135,36 @@ inputEmailPrefix.addEventListener('blur', () => {
|
||||
saveSettings({ silent: true }).catch(() => {});
|
||||
});
|
||||
|
||||
selectMail2925PoolAccount?.addEventListener('change', async () => {
|
||||
try {
|
||||
await syncSelectedMail2925PoolAccount();
|
||||
markSettingsDirty(true);
|
||||
saveSettings({ silent: true }).catch(() => {});
|
||||
} catch (err) {
|
||||
showToast(err.message, 'error');
|
||||
}
|
||||
});
|
||||
|
||||
inputMail2925UseAccountPool?.addEventListener('change', async () => {
|
||||
const enabled = Boolean(inputMail2925UseAccountPool.checked);
|
||||
syncLatestState({ mail2925UseAccountPool: enabled });
|
||||
if (enabled) {
|
||||
syncMail2925PoolAccountOptions(latestState);
|
||||
if (!selectMail2925PoolAccount.value && getMail2925Accounts().length > 0) {
|
||||
selectMail2925PoolAccount.value = String(getMail2925Accounts()[0]?.id || '');
|
||||
}
|
||||
try {
|
||||
await syncSelectedMail2925PoolAccount({ silent: true });
|
||||
} catch (err) {
|
||||
showToast(err.message, 'error');
|
||||
}
|
||||
}
|
||||
setManagedAliasBaseEmailInputForProvider('2925', latestState);
|
||||
updateMailProviderUI();
|
||||
markSettingsDirty(true);
|
||||
saveSettings({ silent: true }).catch(() => {});
|
||||
});
|
||||
|
||||
inputInbucketMailbox.addEventListener('input', () => {
|
||||
markSettingsDirty(true);
|
||||
scheduleSettingsAutoSave();
|
||||
@@ -4207,6 +4416,7 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
||||
updateProgressCounter();
|
||||
updateButtonStates();
|
||||
renderHotmailAccounts();
|
||||
renderMail2925Accounts();
|
||||
if (isLuckmailProvider()) {
|
||||
queueLuckmailPurchaseRefresh();
|
||||
}
|
||||
@@ -4261,6 +4471,12 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
||||
inputEmail.value = getCurrentHotmailEmail();
|
||||
}
|
||||
}
|
||||
if (message.payload.currentMail2925AccountId !== undefined || message.payload.mail2925Accounts !== undefined) {
|
||||
renderMail2925Accounts();
|
||||
if (selectMailProvider.value === '2925') {
|
||||
setManagedAliasBaseEmailInputForProvider('2925', latestState);
|
||||
}
|
||||
}
|
||||
if (message.payload.luckmailApiKey !== undefined) {
|
||||
inputLuckmailApiKey.value = message.payload.luckmailApiKey || '';
|
||||
}
|
||||
@@ -4421,6 +4637,7 @@ document.addEventListener('keydown', (event) => {
|
||||
initializeManualStepActions();
|
||||
initTheme();
|
||||
initHotmailListExpandedState();
|
||||
initMail2925ListExpandedState();
|
||||
updateSaveButtonState();
|
||||
updateConfigMenuControls();
|
||||
setLocalCpaStep9Mode(DEFAULT_LOCAL_CPA_STEP9_MODE);
|
||||
|
||||
Reference in New Issue
Block a user