优化 Cloudflare Temp Email 子域模式配置

This commit is contained in:
QLHazyCoder
2026-05-28 02:59:19 +08:00
parent d63733809a
commit b4df982c37
8 changed files with 458 additions and 104 deletions
+36
View File
@@ -1378,6 +1378,10 @@ header {
} }
.data-input::placeholder { color: var(--text-muted); } .data-input::placeholder { color: var(--text-muted); }
.data-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); } .data-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
.data-input.is-invalid {
border-color: var(--red);
box-shadow: 0 0 0 3px var(--red-soft);
}
.data-textarea { .data-textarea {
width: 100%; width: 100%;
@@ -1490,6 +1494,38 @@ header {
color: var(--text-muted); color: var(--text-muted);
} }
.temp-email-subdomain-mode-wrap,
.temp-email-subdomain-prefix-wrap {
align-items: flex-start;
flex-direction: column;
}
.temp-email-subdomain-mode-wrap .choice-group,
.temp-email-subdomain-prefix-wrap .data-input {
width: 100%;
}
.temp-email-subdomain-mode-wrap .setting-caption {
white-space: normal;
text-align: left;
}
.field-feedback {
min-height: 15px;
font-size: 12px;
font-weight: 600;
line-height: 1.25;
color: var(--text-muted);
}
.field-feedback.is-error {
color: var(--red);
}
.field-feedback-muted {
color: var(--text-secondary);
}
#btn-fetch-email, #btn-fetch-email,
#btn-save-settings { #btn-save-settings {
padding-inline: 10px; padding-inline: 10px;
+22 -29
View File
@@ -812,41 +812,34 @@
<input type="text" id="input-temp-email-receive-mailbox" class="data-input" <input type="text" id="input-temp-email-receive-mailbox" class="data-input"
placeholder="用于接收转发邮件的邮箱,例如 1@email.example.com" /> placeholder="用于接收转发邮件的邮箱,例如 1@email.example.com" />
</div> </div>
<div class="data-row" id="row-temp-email-random-subdomain-toggle" style="display:none;"> <div class="data-row" id="row-temp-email-subdomain-mode" style="display:none;">
<span class="data-label">随机子域</span> <span class="data-label">子域模式</span>
<div class="data-inline"> <div class="data-inline temp-email-subdomain-mode-wrap">
<label class="toggle-switch" for="input-temp-email-use-random-subdomain" <input type="checkbox" id="input-temp-email-use-random-subdomain" hidden />
title="依赖后端 RANDOM_SUBDOMAIN_DOMAINS 配置"> <input type="checkbox" id="input-temp-email-use-fixed-subdomain" hidden />
<input type="checkbox" id="input-temp-email-use-random-subdomain" /> <div id="temp-email-subdomain-mode-group" class="choice-group" role="group"
<span class="toggle-switch-track" aria-hidden="true"> aria-label="Cloudflare Temp Email 子域模式">
<span class="toggle-switch-thumb"></span> <button type="button" class="choice-btn" data-temp-email-subdomain-mode="none">不使用</button>
</span> <button type="button" class="choice-btn" data-temp-email-subdomain-mode="random"
<span>启用</span> title="依赖后端 RANDOM_SUBDOMAIN_DOMAINS 配置">随机</button>
</label> <button type="button" class="choice-btn" data-temp-email-subdomain-mode="fixed"
<span class="setting-caption">依赖后端 RANDOM_SUBDOMAIN_DOMAINS</span> title="依赖后端 ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH 配置">固定</button>
</div> </div>
</div> <span id="temp-email-subdomain-mode-caption" class="setting-caption setting-caption-left">按基础域名直接生成</span>
<div class="data-row" id="row-temp-email-fixed-subdomain-toggle" style="display:none;">
<span class="data-label">固定子域</span>
<div class="data-inline">
<label class="toggle-switch" for="input-temp-email-use-fixed-subdomain"
title="依赖后端 ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH 配置">
<input type="checkbox" id="input-temp-email-use-fixed-subdomain" />
<span class="toggle-switch-track" aria-hidden="true">
<span class="toggle-switch-thumb"></span>
</span>
<span>启用</span>
</label>
<span class="setting-caption">与随机子域互斥</span>
</div> </div>
</div> </div>
<div class="data-row" id="row-temp-email-fixed-subdomain-prefix" style="display:none;"> <div class="data-row" id="row-temp-email-fixed-subdomain-prefix" style="display:none;">
<span class="data-label">子域前缀</span> <span class="data-label">子域前缀</span>
<input type="text" id="input-temp-email-subdomain-prefix" class="data-input" <div class="data-inline temp-email-subdomain-prefix-wrap">
placeholder="例如 a;当前域名为 b.com 时生成 xxx@a.b.com" /> <input type="text" id="input-temp-email-subdomain-prefix" class="data-input"
placeholder="例如 team;基础域名为 mail.example.com 时生成 xxx@team.mail.example.com"
aria-describedby="temp-email-subdomain-prefix-feedback temp-email-effective-domain-preview" />
<span id="temp-email-subdomain-prefix-feedback" class="field-feedback" aria-live="polite"></span>
<span id="temp-email-effective-domain-preview" class="field-feedback field-feedback-muted"></span>
</div>
</div> </div>
<div class="data-row" id="row-temp-email-domain" style="display:none;"> <div class="data-row" id="row-temp-email-domain" style="display:none;">
<span class="data-label">Temp 域名</span> <span class="data-label" id="label-temp-email-domain">Temp 域名</span>
<div class="data-inline"> <div class="data-inline">
<input type="hidden" id="select-temp-email-domain" value="" /> <input type="hidden" id="select-temp-email-domain" value="" />
<div id="temp-email-domain-picker" class="editable-list-picker"> <div id="temp-email-domain-picker" class="editable-list-picker">
+180 -61
View File
@@ -297,13 +297,17 @@ const rowTempEmailLookupMode = document.getElementById('row-temp-email-lookup-mo
const tempEmailLookupModeButtons = Array.from(document.querySelectorAll('[data-temp-email-lookup-mode]')); const tempEmailLookupModeButtons = Array.from(document.querySelectorAll('[data-temp-email-lookup-mode]'));
const rowTempEmailReceiveMailbox = document.getElementById('row-temp-email-receive-mailbox'); const rowTempEmailReceiveMailbox = document.getElementById('row-temp-email-receive-mailbox');
const inputTempEmailReceiveMailbox = document.getElementById('input-temp-email-receive-mailbox'); const inputTempEmailReceiveMailbox = document.getElementById('input-temp-email-receive-mailbox');
const rowTempEmailRandomSubdomainToggle = document.getElementById('row-temp-email-random-subdomain-toggle'); const rowTempEmailSubdomainMode = document.getElementById('row-temp-email-subdomain-mode');
const tempEmailSubdomainModeButtons = Array.from(document.querySelectorAll('[data-temp-email-subdomain-mode]'));
const tempEmailSubdomainModeCaption = document.getElementById('temp-email-subdomain-mode-caption');
const inputTempEmailUseRandomSubdomain = document.getElementById('input-temp-email-use-random-subdomain'); const inputTempEmailUseRandomSubdomain = document.getElementById('input-temp-email-use-random-subdomain');
const rowTempEmailFixedSubdomainToggle = document.getElementById('row-temp-email-fixed-subdomain-toggle');
const inputTempEmailUseFixedSubdomain = document.getElementById('input-temp-email-use-fixed-subdomain'); const inputTempEmailUseFixedSubdomain = document.getElementById('input-temp-email-use-fixed-subdomain');
const rowTempEmailFixedSubdomainPrefix = document.getElementById('row-temp-email-fixed-subdomain-prefix'); const rowTempEmailFixedSubdomainPrefix = document.getElementById('row-temp-email-fixed-subdomain-prefix');
const inputTempEmailSubdomainPrefix = document.getElementById('input-temp-email-subdomain-prefix'); const inputTempEmailSubdomainPrefix = document.getElementById('input-temp-email-subdomain-prefix');
const tempEmailSubdomainPrefixFeedback = document.getElementById('temp-email-subdomain-prefix-feedback');
const tempEmailEffectiveDomainPreview = document.getElementById('temp-email-effective-domain-preview');
const rowTempEmailDomain = document.getElementById('row-temp-email-domain'); const rowTempEmailDomain = document.getElementById('row-temp-email-domain');
const labelTempEmailDomain = document.getElementById('label-temp-email-domain');
const selectTempEmailDomain = document.getElementById('select-temp-email-domain'); const selectTempEmailDomain = document.getElementById('select-temp-email-domain');
const tempEmailDomainPickerRoot = document.getElementById('temp-email-domain-picker'); const tempEmailDomainPickerRoot = document.getElementById('temp-email-domain-picker');
const btnTempEmailDomainMenu = document.getElementById('btn-temp-email-domain-menu'); const btnTempEmailDomainMenu = document.getElementById('btn-temp-email-domain-menu');
@@ -829,6 +833,10 @@ const DEFAULT_MAIL_2925_MODE = MAIL_2925_MODE_PROVIDE;
const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_RECEIVE_MAILBOX = 'receive-mailbox'; const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_RECEIVE_MAILBOX = 'receive-mailbox';
const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_REGISTRATION_EMAIL = 'registration-email'; const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_REGISTRATION_EMAIL = 'registration-email';
const DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE = CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_RECEIVE_MAILBOX; const DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE = CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_RECEIVE_MAILBOX;
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_NONE = 'none';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM = 'random';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED = 'fixed';
const DEFAULT_CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE = CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_NONE;
const NEW_USER_GUIDE_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-new-user-guide-prompt-dismissed'; const NEW_USER_GUIDE_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-new-user-guide-prompt-dismissed';
const AUTO_SKIP_FAILURES_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-skip-failures-prompt-dismissed'; 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_PROMPT_DISMISSED_STORAGE_KEY = 'multipage-auto-run-fallback-risk-prompt-dismissed';
@@ -4117,6 +4125,33 @@ function buildCloudflareTempEmailEffectiveDomainValue(domain = '', subdomainPref
return normalizedPrefix ? `${normalizedPrefix}.${normalizedDomain}` : normalizedDomain; return normalizedPrefix ? `${normalizedPrefix}.${normalizedDomain}` : normalizedDomain;
} }
function getCloudflareTempEmailSubdomainPrefixValidation(value = '') {
const raw = String(value || '').trim();
if (!raw) {
return {
raw,
normalized: '',
valid: false,
message: '请填写子域前缀',
};
}
const normalized = normalizeCloudflareTempEmailSubdomainPrefixValue(raw);
if (!normalized) {
return {
raw,
normalized: '',
valid: false,
message: '仅支持 1-63 位字母、数字或中划线,且不能以中划线开头或结尾',
};
}
return {
raw,
normalized,
valid: true,
message: '',
};
}
function normalizeCloudflareTempEmailDomains(values = []) { function normalizeCloudflareTempEmailDomains(values = []) {
const seen = new Set(); const seen = new Set();
const domains = []; const domains = [];
@@ -4206,13 +4241,13 @@ function applyCloudflareTempEmailSettingsState(state = {}) {
inputTempEmailCustomAuth.value = state?.cloudflareTempEmailCustomAuth || ''; inputTempEmailCustomAuth.value = state?.cloudflareTempEmailCustomAuth || '';
inputTempEmailReceiveMailbox.value = state?.cloudflareTempEmailReceiveMailbox || ''; inputTempEmailReceiveMailbox.value = state?.cloudflareTempEmailReceiveMailbox || '';
setCloudflareTempEmailLookupMode(state?.cloudflareTempEmailLookupMode); setCloudflareTempEmailLookupMode(state?.cloudflareTempEmailLookupMode);
if (inputTempEmailUseRandomSubdomain) { setCloudflareTempEmailSubdomainMode(
inputTempEmailUseRandomSubdomain.checked = Boolean(state?.cloudflareTempEmailUseRandomSubdomain) state?.cloudflareTempEmailUseFixedSubdomain
&& !Boolean(state?.cloudflareTempEmailUseFixedSubdomain); ? CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED
} : (state?.cloudflareTempEmailUseRandomSubdomain
if (inputTempEmailUseFixedSubdomain) { ? CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM
inputTempEmailUseFixedSubdomain.checked = Boolean(state?.cloudflareTempEmailUseFixedSubdomain); : CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_NONE)
} );
if (inputTempEmailSubdomainPrefix) { if (inputTempEmailSubdomainPrefix) {
inputTempEmailSubdomainPrefix.value = normalizeCloudflareTempEmailSubdomainPrefixValue( inputTempEmailSubdomainPrefix.value = normalizeCloudflareTempEmailSubdomainPrefixValue(
state?.cloudflareTempEmailSubdomainPrefix || '' state?.cloudflareTempEmailSubdomainPrefix || ''
@@ -4267,6 +4302,7 @@ function collectSettingsPayload() {
const selectedCloudflareTempEmailDomain = normalizeCloudflareTempEmailDomainValue( const selectedCloudflareTempEmailDomain = normalizeCloudflareTempEmailDomainValue(
!cloudflareTempEmailDomainEditMode ? selectTempEmailDomain.value : tempEmailActiveDomain !cloudflareTempEmailDomainEditMode ? selectTempEmailDomain.value : tempEmailActiveDomain
) || tempEmailActiveDomain; ) || tempEmailActiveDomain;
const cloudflareTempEmailSubdomainMode = getSelectedCloudflareTempEmailSubdomainMode();
const normalizeCloudMailBaseUrlInput = typeof normalizeCloudMailBaseUrlValue === 'function' const normalizeCloudMailBaseUrlInput = typeof normalizeCloudMailBaseUrlValue === 'function'
? normalizeCloudMailBaseUrlValue ? normalizeCloudMailBaseUrlValue
: normalizeCloudflareTempEmailBaseUrlValue; : normalizeCloudflareTempEmailBaseUrlValue;
@@ -5162,9 +5198,10 @@ function collectSettingsPayload() {
? getSelectedCloudflareTempEmailLookupMode() ? getSelectedCloudflareTempEmailLookupMode()
: 'receive-mailbox', : 'receive-mailbox',
cloudflareTempEmailReceiveMailbox: normalizeCloudflareTempEmailReceiveMailboxValue(inputTempEmailReceiveMailbox.value), cloudflareTempEmailReceiveMailbox: normalizeCloudflareTempEmailReceiveMailboxValue(inputTempEmailReceiveMailbox.value),
cloudflareTempEmailUseRandomSubdomain: Boolean(inputTempEmailUseRandomSubdomain?.checked) cloudflareTempEmailUseRandomSubdomain: cloudflareTempEmailSubdomainMode
&& !Boolean(inputTempEmailUseFixedSubdomain?.checked), === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM,
cloudflareTempEmailUseFixedSubdomain: Boolean(inputTempEmailUseFixedSubdomain?.checked), cloudflareTempEmailUseFixedSubdomain: cloudflareTempEmailSubdomainMode
=== CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED,
cloudflareTempEmailSubdomainPrefix: normalizeCloudflareTempEmailSubdomainPrefixValue( cloudflareTempEmailSubdomainPrefix: normalizeCloudflareTempEmailSubdomainPrefixValue(
inputTempEmailSubdomainPrefix?.value || '' inputTempEmailSubdomainPrefix?.value || ''
), ),
@@ -5248,6 +5285,17 @@ function normalizeCloudflareTempEmailLookupMode(value = '') {
: DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE; : DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE;
} }
function normalizeCloudflareTempEmailSubdomainMode(value = '') {
const normalized = String(value || '').trim().toLowerCase();
if (normalized === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM) {
return CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM;
}
if (normalized === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED) {
return CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED;
}
return DEFAULT_CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE;
}
function normalizeHotmailServiceMode(value = '') { function normalizeHotmailServiceMode(value = '') {
if (typeof normalizeHotmailServiceModeFromUtils === 'function') { if (typeof normalizeHotmailServiceModeFromUtils === 'function') {
return normalizeHotmailServiceModeFromUtils(value); return normalizeHotmailServiceModeFromUtils(value);
@@ -8881,6 +8929,37 @@ function setCloudflareTempEmailLookupMode(mode) {
}); });
} }
function syncCloudflareTempEmailSubdomainModeButtons(mode) {
const resolvedMode = normalizeCloudflareTempEmailSubdomainMode(mode);
tempEmailSubdomainModeButtons.forEach((button) => {
const active = button.dataset.tempEmailSubdomainMode === resolvedMode;
button.classList.toggle('is-active', active);
button.setAttribute('aria-pressed', String(active));
});
}
function getSelectedCloudflareTempEmailSubdomainMode() {
if (inputTempEmailUseFixedSubdomain?.checked) {
return CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED;
}
if (inputTempEmailUseRandomSubdomain?.checked) {
return CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM;
}
const activeButton = tempEmailSubdomainModeButtons.find((button) => button.classList.contains('is-active'));
return normalizeCloudflareTempEmailSubdomainMode(activeButton?.dataset.tempEmailSubdomainMode);
}
function setCloudflareTempEmailSubdomainMode(mode) {
const resolvedMode = normalizeCloudflareTempEmailSubdomainMode(mode);
if (inputTempEmailUseRandomSubdomain) {
inputTempEmailUseRandomSubdomain.checked = resolvedMode === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM;
}
if (inputTempEmailUseFixedSubdomain) {
inputTempEmailUseFixedSubdomain.checked = resolvedMode === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED;
}
syncCloudflareTempEmailSubdomainModeButtons(resolvedMode);
}
function getSelectedHotmailServiceMode() { function getSelectedHotmailServiceMode() {
const activeButton = hotmailServiceModeButtons.find((button) => button.classList.contains('is-active')); const activeButton = hotmailServiceModeButtons.find((button) => button.classList.contains('is-active'));
return normalizeHotmailServiceMode(activeButton?.dataset.hotmailServiceMode); return normalizeHotmailServiceMode(activeButton?.dataset.hotmailServiceMode);
@@ -12997,11 +13076,26 @@ function updateMailProviderUI() {
const isIcloudComCnHost = selectedIcloudHost === 'icloud.com.cn'; const isIcloudComCnHost = selectedIcloudHost === 'icloud.com.cn';
const showIcloudTargetMailboxType = useIcloudProvider; const showIcloudTargetMailboxType = useIcloudProvider;
const showIcloudForwardMailProvider = useIcloudProvider && icloudTargetMailboxType === 'forward-mailbox'; const showIcloudForwardMailProvider = useIcloudProvider && icloudTargetMailboxType === 'forward-mailbox';
const showCloudflareTempEmailRandomSubdomainToggle = useEmailGenerator && useCloudflareTempEmailGenerator; const showCloudflareTempEmailSubdomainMode = useEmailGenerator && useCloudflareTempEmailGenerator;
const showCloudflareTempEmailFixedSubdomainToggle = useEmailGenerator && useCloudflareTempEmailGenerator; const cloudflareTempEmailSubdomainMode = getSelectedCloudflareTempEmailSubdomainMode();
const showCloudflareTempEmailFixedSubdomainPrefix = showCloudflareTempEmailFixedSubdomainToggle syncCloudflareTempEmailSubdomainModeButtons(cloudflareTempEmailSubdomainMode);
&& Boolean(inputTempEmailUseFixedSubdomain?.checked); const showCloudflareTempEmailFixedSubdomainPrefix = showCloudflareTempEmailSubdomainMode
&& cloudflareTempEmailSubdomainMode === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED;
const showCloudflareTempEmailDomain = useEmailGenerator && useCloudflareTempEmailGenerator; const showCloudflareTempEmailDomain = useEmailGenerator && useCloudflareTempEmailGenerator;
const { domains: tempEmailDomains, activeDomain: tempEmailActiveDomain } = getCloudflareTempEmailDomainsFromState();
const selectedTempEmailDomain = normalizeCloudflareTempEmailDomainValue(
selectTempEmailDomain?.value || tempEmailActiveDomain
) || tempEmailActiveDomain;
const fixedSubdomainValidation = getCloudflareTempEmailSubdomainPrefixValidation(
inputTempEmailSubdomainPrefix?.value || ''
);
const fixedSubdomainConfigInvalid = showCloudflareTempEmailFixedSubdomainPrefix
&& !fixedSubdomainValidation.valid;
const tempEmailEffectiveDomain = buildCloudflareTempEmailEffectiveDomainValue(
selectedTempEmailDomain,
fixedSubdomainValidation.normalized,
{ requirePrefix: true }
);
if (rowEmailGenerator) { if (rowEmailGenerator) {
rowEmailGenerator.style.display = useEmailGenerator ? '' : 'none'; rowEmailGenerator.style.display = useEmailGenerator ? '' : 'none';
} }
@@ -13057,17 +13151,38 @@ function updateMailProviderUI() {
rowTempEmailLookupMode.style.display = showCloudflareTempEmailLookupMode ? '' : 'none'; rowTempEmailLookupMode.style.display = showCloudflareTempEmailLookupMode ? '' : 'none';
} }
rowTempEmailReceiveMailbox.style.display = showCloudflareTempEmailReceiveMailbox ? '' : 'none'; rowTempEmailReceiveMailbox.style.display = showCloudflareTempEmailReceiveMailbox ? '' : 'none';
if (rowTempEmailRandomSubdomainToggle) { if (rowTempEmailSubdomainMode) {
rowTempEmailRandomSubdomainToggle.style.display = showCloudflareTempEmailRandomSubdomainToggle ? '' : 'none'; rowTempEmailSubdomainMode.style.display = showCloudflareTempEmailSubdomainMode ? '' : 'none';
} }
if (rowTempEmailFixedSubdomainToggle) { if (tempEmailSubdomainModeCaption) {
rowTempEmailFixedSubdomainToggle.style.display = showCloudflareTempEmailFixedSubdomainToggle ? '' : 'none'; tempEmailSubdomainModeCaption.textContent = cloudflareTempEmailSubdomainMode === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM
? '需后端、DNS、Email Routing/MX 覆盖随机子域'
: (cloudflareTempEmailSubdomainMode === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED
? '需后端、DNS、Email Routing/MX 覆盖固定子域'
: '按基础域名直接生成');
} }
if (rowTempEmailFixedSubdomainPrefix) { if (rowTempEmailFixedSubdomainPrefix) {
rowTempEmailFixedSubdomainPrefix.style.display = showCloudflareTempEmailFixedSubdomainPrefix ? '' : 'none'; rowTempEmailFixedSubdomainPrefix.style.display = showCloudflareTempEmailFixedSubdomainPrefix ? '' : 'none';
} }
if (inputTempEmailSubdomainPrefix) {
inputTempEmailSubdomainPrefix.classList.toggle('is-invalid', fixedSubdomainConfigInvalid);
inputTempEmailSubdomainPrefix.setAttribute('aria-invalid', String(fixedSubdomainConfigInvalid));
}
if (tempEmailSubdomainPrefixFeedback) {
tempEmailSubdomainPrefixFeedback.textContent = fixedSubdomainConfigInvalid
? fixedSubdomainValidation.message
: '';
tempEmailSubdomainPrefixFeedback.classList.toggle('is-error', fixedSubdomainConfigInvalid);
}
if (tempEmailEffectiveDomainPreview) {
tempEmailEffectiveDomainPreview.textContent = showCloudflareTempEmailFixedSubdomainPrefix && tempEmailEffectiveDomain
? `最终域名:${tempEmailEffectiveDomain}`
: '';
}
rowTempEmailDomain.style.display = showCloudflareTempEmailDomain ? '' : 'none'; rowTempEmailDomain.style.display = showCloudflareTempEmailDomain ? '' : 'none';
const { domains: tempEmailDomains } = getCloudflareTempEmailDomainsFromState(); if (labelTempEmailDomain) {
labelTempEmailDomain.textContent = showCloudflareTempEmailFixedSubdomainPrefix ? '基础域名' : 'Temp 域名';
}
if (showCloudflareTempEmailDomain) { if (showCloudflareTempEmailDomain) {
setCloudflareTempEmailDomainEditMode(cloudflareTempEmailDomainEditMode || tempEmailDomains.length === 0, { clearInput: false }); setCloudflareTempEmailDomainEditMode(cloudflareTempEmailDomainEditMode || tempEmailDomains.length === 0, { clearInput: false });
} else { } else {
@@ -13127,7 +13242,7 @@ function updateMailProviderUI() {
if (useCustomEmail && useCustomMailProviderPool) { if (useCustomEmail && useCustomMailProviderPool) {
inputEmail.placeholder = '号池会按顺序自动回填当前轮邮箱,也可以手动覆盖'; inputEmail.placeholder = '号池会按顺序自动回填当前轮邮箱,也可以手动覆盖';
} }
btnFetchEmail.disabled = useLuckmail || useCustomEmail || useCustomEmailPool || isAutoRunLockedPhase(); btnFetchEmail.disabled = useLuckmail || useCustomEmail || useCustomEmailPool || fixedSubdomainConfigInvalid || isAutoRunLockedPhase();
if (!btnFetchEmail.disabled) { if (!btnFetchEmail.disabled) {
btnFetchEmail.textContent = uiCopy.buttonLabel; btnFetchEmail.textContent = uiCopy.buttonLabel;
} }
@@ -13164,19 +13279,17 @@ function updateMailProviderUI() {
if (autoHintText && showCloudflareTempEmailReceiveMailbox && !useCustomEmailPool) { if (autoHintText && showCloudflareTempEmailReceiveMailbox && !useCustomEmailPool) {
autoHintText.textContent = '若注册邮箱会转发到 Cloudflare Temp Email,请在“邮件接收”中填写实际接收转发邮件的邮箱。'; autoHintText.textContent = '若注册邮箱会转发到 Cloudflare Temp Email,请在“邮件接收”中填写实际接收转发邮件的邮箱。';
} }
if (autoHintText && showCloudflareTempEmailRandomSubdomainToggle && inputTempEmailUseRandomSubdomain?.checked) { if (
autoHintText.textContent = '已启用随机子域名:扩展会按当前选中的 Temp 域名提交,并额外携带 enableRandomSubdomain;是否生效取决于后端 RANDOM_SUBDOMAIN_DOMAINS 配置。'; autoHintText
&& showCloudflareTempEmailSubdomainMode
&& cloudflareTempEmailSubdomainMode === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM
) {
autoHintText.textContent = '已启用随机子域名:扩展会按当前选中的基础域名提交,并额外携带 enableRandomSubdomain;后端 RANDOM_SUBDOMAIN_DOMAINS、DNS、Email Routing/MX 都需要覆盖对应子域。';
} }
if (autoHintText && showCloudflareTempEmailFixedSubdomainPrefix && inputTempEmailUseFixedSubdomain?.checked) { if (autoHintText && showCloudflareTempEmailFixedSubdomainPrefix) {
const { activeDomain: tempEmailActiveDomain } = getCloudflareTempEmailDomainsFromState(); autoHintText.textContent = tempEmailEffectiveDomain
const effectiveDomain = buildCloudflareTempEmailEffectiveDomainValue( ? `已启用固定子域名:本次会向后端提交 ${tempEmailEffectiveDomain};后端 ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH、DNS、Email Routing/MX 都需要覆盖该子域。`
selectTempEmailDomain?.value || tempEmailActiveDomain, : `已启用固定子域名:${fixedSubdomainValidation.message};后端、DNS、Email Routing/MX 都需要覆盖该子域。`;
inputTempEmailSubdomainPrefix?.value || '',
{ requirePrefix: true }
);
autoHintText.textContent = effectiveDomain
? `已启用固定子域名:本次会向后端提交 ${effectiveDomain},后端需开启 ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH。`
: '已启用固定子域名:请填写有效的子域前缀;后端需开启 ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH。';
} }
if (autoHintText && useIcloudProvider && showIcloudForwardMailProvider) { if (autoHintText && useIcloudProvider && showIcloudForwardMailProvider) {
const forwardProvider = normalizeIcloudForwardMailProvider(icloudForwardMailProviderValue); const forwardProvider = normalizeIcloudForwardMailProvider(icloudForwardMailProviderValue);
@@ -16566,24 +16679,19 @@ inputTempEmailReceiveMailbox.addEventListener('blur', () => {
saveSettings({ silent: true }).catch(() => { }); saveSettings({ silent: true }).catch(() => { });
}); });
inputTempEmailUseRandomSubdomain?.addEventListener('change', () => { tempEmailSubdomainModeButtons.forEach((button) => {
if (inputTempEmailUseRandomSubdomain.checked && inputTempEmailUseFixedSubdomain) { button.addEventListener('click', () => {
inputTempEmailUseFixedSubdomain.checked = false; const nextMode = normalizeCloudflareTempEmailSubdomainMode(button.dataset.tempEmailSubdomainMode);
} const previousMode = getSelectedCloudflareTempEmailSubdomainMode();
updateMailProviderUI(); if (nextMode === previousMode) {
clearRegistrationEmail({ silent: true }).catch(() => { }); return;
markSettingsDirty(true); }
saveSettings({ silent: true }).catch(() => { }); setCloudflareTempEmailSubdomainMode(nextMode);
}); updateMailProviderUI();
clearRegistrationEmail({ silent: true }).catch(() => { });
inputTempEmailUseFixedSubdomain?.addEventListener('change', () => { markSettingsDirty(true);
if (inputTempEmailUseFixedSubdomain.checked && inputTempEmailUseRandomSubdomain) { saveSettings({ silent: true }).catch(() => { });
inputTempEmailUseRandomSubdomain.checked = false; });
}
updateMailProviderUI();
clearRegistrationEmail({ silent: true }).catch(() => { });
markSettingsDirty(true);
saveSettings({ silent: true }).catch(() => { });
}); });
inputTempEmailSubdomainPrefix?.addEventListener('input', () => { inputTempEmailSubdomainPrefix?.addEventListener('input', () => {
@@ -17772,15 +17880,25 @@ chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
if (message.payload.cloudflareTempEmailReceiveMailbox !== undefined) { if (message.payload.cloudflareTempEmailReceiveMailbox !== undefined) {
inputTempEmailReceiveMailbox.value = message.payload.cloudflareTempEmailReceiveMailbox || ''; inputTempEmailReceiveMailbox.value = message.payload.cloudflareTempEmailReceiveMailbox || '';
} }
if (message.payload.cloudflareTempEmailUseRandomSubdomain !== undefined && inputTempEmailUseRandomSubdomain) { if (
inputTempEmailUseRandomSubdomain.checked = Boolean(message.payload.cloudflareTempEmailUseRandomSubdomain) message.payload.cloudflareTempEmailUseRandomSubdomain !== undefined
&& !Boolean(message.payload.cloudflareTempEmailUseFixedSubdomain ?? latestState?.cloudflareTempEmailUseFixedSubdomain); || message.payload.cloudflareTempEmailUseFixedSubdomain !== undefined
} ) {
if (message.payload.cloudflareTempEmailUseFixedSubdomain !== undefined && inputTempEmailUseFixedSubdomain) { const useFixedSubdomain = Boolean(
inputTempEmailUseFixedSubdomain.checked = Boolean(message.payload.cloudflareTempEmailUseFixedSubdomain); message.payload.cloudflareTempEmailUseFixedSubdomain
if (inputTempEmailUseFixedSubdomain.checked && inputTempEmailUseRandomSubdomain) { ?? latestState?.cloudflareTempEmailUseFixedSubdomain
inputTempEmailUseRandomSubdomain.checked = false; );
} const useRandomSubdomain = Boolean(
message.payload.cloudflareTempEmailUseRandomSubdomain
?? latestState?.cloudflareTempEmailUseRandomSubdomain
);
setCloudflareTempEmailSubdomainMode(
useFixedSubdomain
? CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED
: (useRandomSubdomain
? CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM
: CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_NONE)
);
} }
if (message.payload.cloudflareTempEmailSubdomainPrefix !== undefined && inputTempEmailSubdomainPrefix) { if (message.payload.cloudflareTempEmailSubdomainPrefix !== undefined && inputTempEmailSubdomainPrefix) {
inputTempEmailSubdomainPrefix.value = normalizeCloudflareTempEmailSubdomainPrefixValue( inputTempEmailSubdomainPrefix.value = normalizeCloudflareTempEmailSubdomainPrefixValue(
@@ -18398,6 +18516,7 @@ updateConfigMenuControls();
setLocalCpaStep9Mode(DEFAULT_LOCAL_CPA_STEP9_MODE); setLocalCpaStep9Mode(DEFAULT_LOCAL_CPA_STEP9_MODE);
setMail2925Mode(DEFAULT_MAIL_2925_MODE); setMail2925Mode(DEFAULT_MAIL_2925_MODE);
setCloudflareTempEmailLookupMode(DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE); setCloudflareTempEmailLookupMode(DEFAULT_CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE);
setCloudflareTempEmailSubdomainMode(DEFAULT_CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE);
initializeReleaseInfo().catch((err) => { initializeReleaseInfo().catch((err) => {
console.error('Failed to initialize release info:', err); console.error('Failed to initialize release info:', err);
}); });
@@ -58,6 +58,31 @@ function createRow(initialDisplay = 'none') {
}; };
} }
function createClassList(initial = []) {
const values = new Set(initial);
return {
toggle(name, force) {
if (force === undefined) {
if (values.has(name)) {
values.delete(name);
return false;
}
values.add(name);
return true;
}
if (force) {
values.add(name);
return true;
}
values.delete(name);
return false;
},
contains(name) {
return values.has(name);
},
};
}
test('sidepanel html places cloudflare temp email controls in a standalone section', () => { test('sidepanel html places cloudflare temp email controls in a standalone section', () => {
const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8'); const html = fs.readFileSync('sidepanel/sidepanel.html', 'utf8');
assert.match(html, /id="cloudflare-temp-email-section"/); assert.match(html, /id="cloudflare-temp-email-section"/);
@@ -67,13 +92,20 @@ test('sidepanel html places cloudflare temp email controls in a standalone secti
assert.match(html, /id="row-temp-email-lookup-mode"/); assert.match(html, /id="row-temp-email-lookup-mode"/);
assert.match(html, /data-temp-email-lookup-mode="receive-mailbox"/); assert.match(html, /data-temp-email-lookup-mode="receive-mailbox"/);
assert.match(html, /data-temp-email-lookup-mode="registration-email"/); assert.match(html, /data-temp-email-lookup-mode="registration-email"/);
assert.match(html, /id="row-temp-email-random-subdomain-toggle"/); assert.match(html, /id="row-temp-email-subdomain-mode"/);
assert.match(html, /data-temp-email-subdomain-mode="none"/);
assert.match(html, /data-temp-email-subdomain-mode="random"/);
assert.match(html, /data-temp-email-subdomain-mode="fixed"/);
assert.match(html, /id="input-temp-email-use-random-subdomain"/); assert.match(html, /id="input-temp-email-use-random-subdomain"/);
assert.match(html, /id="row-temp-email-fixed-subdomain-toggle"/);
assert.match(html, /id="input-temp-email-use-fixed-subdomain"/); assert.match(html, /id="input-temp-email-use-fixed-subdomain"/);
assert.match(html, /id="row-temp-email-fixed-subdomain-prefix"/); assert.match(html, /id="row-temp-email-fixed-subdomain-prefix"/);
assert.match(html, /id="input-temp-email-subdomain-prefix"/); assert.match(html, /id="input-temp-email-subdomain-prefix"/);
assert.match(html, /id="temp-email-subdomain-prefix-feedback"/);
assert.match(html, /id="temp-email-effective-domain-preview"/);
assert.match(html, /id="label-temp-email-domain"/);
assert.match(html, /id="btn-temp-email-domain-mode"[^>]*>更新</); assert.match(html, /id="btn-temp-email-domain-mode"[^>]*>更新</);
assert.doesNotMatch(html, /id="row-temp-email-random-subdomain-toggle"/);
assert.doesNotMatch(html, /id="row-temp-email-fixed-subdomain-toggle"/);
assert.doesNotMatch(html, /id="row-temp-email-random-subdomain-domain"/); assert.doesNotMatch(html, /id="row-temp-email-random-subdomain-domain"/);
}); });
@@ -148,6 +180,13 @@ const inputTempEmailReceiveMailbox = { value: '' };
const inputTempEmailUseRandomSubdomain = { checked: false }; const inputTempEmailUseRandomSubdomain = { checked: false };
const inputTempEmailUseFixedSubdomain = { checked: false }; const inputTempEmailUseFixedSubdomain = { checked: false };
const inputTempEmailSubdomainPrefix = { value: '' }; const inputTempEmailSubdomainPrefix = { value: '' };
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_NONE = 'none';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM = 'random';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED = 'fixed';
function setCloudflareTempEmailSubdomainMode(mode) {
inputTempEmailUseFixedSubdomain.checked = mode === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED;
inputTempEmailUseRandomSubdomain.checked = mode === CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM;
}
const calls = { const calls = {
domainOptions: [], domainOptions: [],
domainEditMode: [], domainEditMode: [],
@@ -431,10 +470,55 @@ const rowTempEmailAdminAuth = ${JSON.stringify(createRow('none'))};
const rowTempEmailCustomAuth = ${JSON.stringify(createRow('none'))}; const rowTempEmailCustomAuth = ${JSON.stringify(createRow('none'))};
const rowTempEmailLookupMode = ${JSON.stringify(createRow('none'))}; const rowTempEmailLookupMode = ${JSON.stringify(createRow('none'))};
const rowTempEmailReceiveMailbox = ${JSON.stringify(createRow('none'))}; const rowTempEmailReceiveMailbox = ${JSON.stringify(createRow('none'))};
const rowTempEmailRandomSubdomainToggle = ${JSON.stringify(createRow('none'))}; const rowTempEmailSubdomainMode = ${JSON.stringify(createRow('none'))};
const rowTempEmailFixedSubdomainToggle = ${JSON.stringify(createRow('none'))}; function createClassList(initial = []) {
const values = new Set(initial);
return {
toggle(name, force) {
if (force === undefined) {
if (values.has(name)) {
values.delete(name);
return false;
}
values.add(name);
return true;
}
if (force) {
values.add(name);
return true;
}
values.delete(name);
return false;
},
contains(name) {
return values.has(name);
},
};
}
const tempEmailSubdomainModeButtons = [
{
dataset: { tempEmailSubdomainMode: 'none' },
attributes: {},
classList: createClassList(['is-active']),
setAttribute(name, value) { this.attributes[name] = String(value); },
},
{
dataset: { tempEmailSubdomainMode: 'random' },
attributes: {},
classList: createClassList(),
setAttribute(name, value) { this.attributes[name] = String(value); },
},
{
dataset: { tempEmailSubdomainMode: 'fixed' },
attributes: {},
classList: createClassList(),
setAttribute(name, value) { this.attributes[name] = String(value); },
},
];
const tempEmailSubdomainModeCaption = { textContent: '' };
const rowTempEmailFixedSubdomainPrefix = ${JSON.stringify(createRow('none'))}; const rowTempEmailFixedSubdomainPrefix = ${JSON.stringify(createRow('none'))};
const rowTempEmailDomain = ${JSON.stringify(createRow('none'))}; const rowTempEmailDomain = ${JSON.stringify(createRow('none'))};
const labelTempEmailDomain = { textContent: '' };
const cloudflareTempEmailSection = ${JSON.stringify(createRow('none'))}; const cloudflareTempEmailSection = ${JSON.stringify(createRow('none'))};
const hotmailSection = ${JSON.stringify(createRow('none'))}; const hotmailSection = ${JSON.stringify(createRow('none'))};
const mail2925Section = ${JSON.stringify(createRow('none'))}; const mail2925Section = ${JSON.stringify(createRow('none'))};
@@ -457,7 +541,18 @@ const selectEmailGenerator = { value: 'cloudflare-temp-email', disabled: false }
const selectTempEmailDomain = { value: 'mail.example.com' }; const selectTempEmailDomain = { value: 'mail.example.com' };
const inputTempEmailUseRandomSubdomain = { checked: false }; const inputTempEmailUseRandomSubdomain = { checked: false };
const inputTempEmailUseFixedSubdomain = { checked: false }; const inputTempEmailUseFixedSubdomain = { checked: false };
const inputTempEmailSubdomainPrefix = { value: 'team' }; const inputTempEmailSubdomainPrefix = {
value: 'team',
attributes: {},
classList: createClassList(),
setAttribute(name, value) { this.attributes[name] = String(value); },
};
const tempEmailSubdomainPrefixFeedback = { textContent: '', classList: createClassList() };
const tempEmailEffectiveDomainPreview = { textContent: '' };
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_NONE = 'none';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM = 'random';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED = 'fixed';
const DEFAULT_CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE = 'none';
const calls = { const calls = {
tempDomainEditMode: [], tempDomainEditMode: [],
}; };
@@ -468,6 +563,31 @@ function usesGeneratedAliasMailProvider() { return false; }
function getSelectedMail2925Mode() { return 'provide'; } function getSelectedMail2925Mode() { return 'provide'; }
let selectedCloudflareTempEmailLookupMode = 'receive-mailbox'; let selectedCloudflareTempEmailLookupMode = 'receive-mailbox';
function getSelectedCloudflareTempEmailLookupMode() { return selectedCloudflareTempEmailLookupMode; } function getSelectedCloudflareTempEmailLookupMode() { return selectedCloudflareTempEmailLookupMode; }
function normalizeCloudflareTempEmailSubdomainMode(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return ['random', 'fixed'].includes(normalized) ? normalized : 'none';
}
function syncCloudflareTempEmailSubdomainModeButtons(mode) {
const resolvedMode = normalizeCloudflareTempEmailSubdomainMode(mode);
tempEmailSubdomainModeButtons.forEach((button) => {
const active = button.dataset.tempEmailSubdomainMode === resolvedMode;
button.classList.toggle('is-active', active);
button.setAttribute('aria-pressed', String(active));
});
}
function getSelectedCloudflareTempEmailSubdomainMode() {
if (inputTempEmailUseFixedSubdomain.checked) return 'fixed';
if (inputTempEmailUseRandomSubdomain.checked) return 'random';
return 'none';
}
function getCloudflareTempEmailSubdomainPrefixValidation(value = '') {
const raw = String(value || '').trim();
if (!raw) return { raw, normalized: '', valid: false, message: '请填写子域前缀' };
const normalized = normalizeCloudflareTempEmailSubdomainPrefixValue(raw);
return normalized
? { raw, normalized, valid: true, message: '' }
: { raw, normalized: '', valid: false, message: '仅支持 1-63 位字母、数字或中划线,且不能以中划线开头或结尾' };
}
function getManagedAliasProviderUiCopy() { return null; } function getManagedAliasProviderUiCopy() { return null; }
function getCurrentRegistrationEmailUiCopy() { function getCurrentRegistrationEmailUiCopy() {
return { return {
@@ -482,7 +602,10 @@ function getCloudflareDomainsFromState() { return { domains: [], activeDomain: '
function setCloudflareDomainEditMode() {} function setCloudflareDomainEditMode() {}
function getCloudflareTempEmailDomainsFromState() { return { domains: ['mail.example.com'], activeDomain: 'mail.example.com' }; } function getCloudflareTempEmailDomainsFromState() { return { domains: ['mail.example.com'], activeDomain: 'mail.example.com' }; }
function normalizeCloudflareTempEmailDomainValue(value = '') { return String(value || '').trim().toLowerCase(); } function normalizeCloudflareTempEmailDomainValue(value = '') { return String(value || '').trim().toLowerCase(); }
function normalizeCloudflareTempEmailSubdomainPrefixValue(value = '') { return String(value || '').trim().toLowerCase(); } function normalizeCloudflareTempEmailSubdomainPrefixValue(value = '') {
const normalized = String(value || '').trim().toLowerCase();
return /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(normalized) ? normalized : '';
}
function buildCloudflareTempEmailEffectiveDomainValue(domain = '', subdomainPrefix = '', options = {}) { function buildCloudflareTempEmailEffectiveDomainValue(domain = '', subdomainPrefix = '', options = {}) {
const normalizedDomain = normalizeCloudflareTempEmailDomainValue(domain); const normalizedDomain = normalizeCloudflareTempEmailDomainValue(domain);
const normalizedPrefix = normalizeCloudflareTempEmailSubdomainPrefixValue(subdomainPrefix); const normalizedPrefix = normalizeCloudflareTempEmailSubdomainPrefixValue(subdomainPrefix);
@@ -505,13 +628,17 @@ return {
cloudflareTempEmailSection, cloudflareTempEmailSection,
rowTempEmailLookupMode, rowTempEmailLookupMode,
rowTempEmailReceiveMailbox, rowTempEmailReceiveMailbox,
rowTempEmailRandomSubdomainToggle, rowTempEmailSubdomainMode,
rowTempEmailFixedSubdomainToggle,
rowTempEmailFixedSubdomainPrefix, rowTempEmailFixedSubdomainPrefix,
rowTempEmailDomain, rowTempEmailDomain,
labelTempEmailDomain,
inputTempEmailUseRandomSubdomain, inputTempEmailUseRandomSubdomain,
inputTempEmailUseFixedSubdomain, inputTempEmailUseFixedSubdomain,
inputTempEmailSubdomainPrefix, inputTempEmailSubdomainPrefix,
tempEmailSubdomainModeCaption,
tempEmailSubdomainPrefixFeedback,
tempEmailEffectiveDomainPreview,
btnFetchEmail,
selectMailProvider, selectMailProvider,
selectEmailGenerator, selectEmailGenerator,
setLookupMode(value) { setLookupMode(value) {
@@ -524,10 +651,10 @@ return {
api.updateMailProviderUI(); api.updateMailProviderUI();
assert.equal(api.cloudflareTempEmailSection.style.display, ''); assert.equal(api.cloudflareTempEmailSection.style.display, '');
assert.equal(api.rowTempEmailRandomSubdomainToggle.style.display, ''); assert.equal(api.rowTempEmailSubdomainMode.style.display, '');
assert.equal(api.rowTempEmailFixedSubdomainToggle.style.display, '');
assert.equal(api.rowTempEmailFixedSubdomainPrefix.style.display, 'none'); assert.equal(api.rowTempEmailFixedSubdomainPrefix.style.display, 'none');
assert.equal(api.rowTempEmailDomain.style.display, ''); assert.equal(api.rowTempEmailDomain.style.display, '');
assert.equal(api.labelTempEmailDomain.textContent, 'Temp 域名');
api.selectMailProvider.value = 'cloudflare-temp-email'; api.selectMailProvider.value = 'cloudflare-temp-email';
api.selectEmailGenerator.value = 'duck'; api.selectEmailGenerator.value = 'duck';
@@ -548,16 +675,29 @@ return {
assert.equal(api.cloudflareTempEmailSection.style.display, ''); assert.equal(api.cloudflareTempEmailSection.style.display, '');
assert.equal(api.rowTempEmailDomain.style.display, ''); assert.equal(api.rowTempEmailDomain.style.display, '');
assert.match(api.autoHintText.textContent, /RANDOM_SUBDOMAIN_DOMAINS/); assert.match(api.autoHintText.textContent, /RANDOM_SUBDOMAIN_DOMAINS/);
assert.match(api.autoHintText.textContent, /Email Routing\/MX/);
assert.match(api.tempEmailSubdomainModeCaption.textContent, /随机子域/);
api.inputTempEmailUseRandomSubdomain.checked = false; api.inputTempEmailUseRandomSubdomain.checked = false;
api.inputTempEmailUseFixedSubdomain.checked = true; api.inputTempEmailUseFixedSubdomain.checked = true;
api.inputTempEmailSubdomainPrefix.value = 'team'; api.inputTempEmailSubdomainPrefix.value = 'team';
api.updateMailProviderUI(); api.updateMailProviderUI();
assert.equal(api.rowTempEmailFixedSubdomainPrefix.style.display, ''); assert.equal(api.rowTempEmailFixedSubdomainPrefix.style.display, '');
assert.equal(api.labelTempEmailDomain.textContent, '基础域名');
assert.equal(api.tempEmailEffectiveDomainPreview.textContent, '最终域名:team.mail.example.com');
assert.equal(api.tempEmailSubdomainPrefixFeedback.textContent, '');
assert.equal(api.inputTempEmailSubdomainPrefix.attributes['aria-invalid'], 'false');
assert.equal(api.btnFetchEmail.disabled, false);
assert.match(api.autoHintText.textContent, /team\.mail\.example\.com/); assert.match(api.autoHintText.textContent, /team\.mail\.example\.com/);
assert.match(api.autoHintText.textContent, /ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH/); assert.match(api.autoHintText.textContent, /ENABLE_CREATE_ADDRESS_SUBDOMAIN_MATCH/);
assert.match(api.autoHintText.textContent, /Email Routing\/MX/);
api.inputTempEmailSubdomainPrefix.value = ''; api.inputTempEmailSubdomainPrefix.value = '';
api.updateMailProviderUI(); api.updateMailProviderUI();
assert.match(api.autoHintText.textContent, /请填写有效的子域前缀/); assert.equal(api.btnFetchEmail.disabled, true);
assert.equal(api.tempEmailEffectiveDomainPreview.textContent, '');
assert.equal(api.tempEmailSubdomainPrefixFeedback.textContent, '请填写子域前缀');
assert.equal(api.tempEmailSubdomainPrefixFeedback.classList.contains('is-error'), true);
assert.equal(api.inputTempEmailSubdomainPrefix.attributes['aria-invalid'], 'true');
assert.match(api.autoHintText.textContent, /请填写子域前缀/);
}); });
@@ -247,6 +247,13 @@ const inputTempEmailReceiveMailbox = { value: 'relay@example.com' };
const inputTempEmailUseRandomSubdomain = { checked: true }; const inputTempEmailUseRandomSubdomain = { checked: true };
const inputTempEmailUseFixedSubdomain = { checked: false }; const inputTempEmailUseFixedSubdomain = { checked: false };
const inputTempEmailSubdomainPrefix = { value: '' }; const inputTempEmailSubdomainPrefix = { value: '' };
function getSelectedCloudflareTempEmailSubdomainMode() {
if (inputTempEmailUseFixedSubdomain.checked) return 'fixed';
if (inputTempEmailUseRandomSubdomain.checked) return 'random';
return 'none';
}
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM = 'random';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED = 'fixed';
const inputAutoSkipFailures = { checked: false }; const inputAutoSkipFailures = { checked: false };
const inputAutoSkipFailuresThreadIntervalMinutes = { value: '5' }; const inputAutoSkipFailuresThreadIntervalMinutes = { value: '5' };
const inputAutoStepDelaySeconds = { value: '10' }; const inputAutoStepDelaySeconds = { value: '10' };
+48 -3
View File
@@ -132,6 +132,13 @@ const inputTempEmailReceiveMailbox = { value: '' };
const inputTempEmailUseRandomSubdomain = { checked: false }; const inputTempEmailUseRandomSubdomain = { checked: false };
const inputTempEmailUseFixedSubdomain = { checked: false }; const inputTempEmailUseFixedSubdomain = { checked: false };
const inputTempEmailSubdomainPrefix = { value: '' }; const inputTempEmailSubdomainPrefix = { value: '' };
function getSelectedCloudflareTempEmailSubdomainMode() {
if (inputTempEmailUseFixedSubdomain.checked) return 'fixed';
if (inputTempEmailUseRandomSubdomain.checked) return 'random';
return 'none';
}
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM = 'random';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED = 'fixed';
const inputAutoSkipFailures = { checked: false }; const inputAutoSkipFailures = { checked: false };
const inputAutoSkipFailuresThreadIntervalMinutes = { value: '0' }; const inputAutoSkipFailuresThreadIntervalMinutes = { value: '0' };
const inputAutoStepDelaySeconds = { value: '' }; const inputAutoStepDelaySeconds = { value: '' };
@@ -275,10 +282,13 @@ const rowTempEmailBaseUrl = createRow();
const rowTempEmailAdminAuth = createRow(); const rowTempEmailAdminAuth = createRow();
const rowTempEmailCustomAuth = createRow(); const rowTempEmailCustomAuth = createRow();
const rowTempEmailReceiveMailbox = createRow(); const rowTempEmailReceiveMailbox = createRow();
const rowTempEmailRandomSubdomainToggle = createRow(); const rowTempEmailLookupMode = createRow();
const rowTempEmailFixedSubdomainToggle = createRow(); const rowTempEmailSubdomainMode = createRow();
const tempEmailSubdomainModeButtons = [];
const tempEmailSubdomainModeCaption = { textContent: '' };
const rowTempEmailFixedSubdomainPrefix = createRow(); const rowTempEmailFixedSubdomainPrefix = createRow();
const rowTempEmailDomain = createRow(); const rowTempEmailDomain = createRow();
const labelTempEmailDomain = { textContent: '' };
const cloudflareTempEmailSection = createRow(); const cloudflareTempEmailSection = createRow();
const hotmailSection = createRow(); const hotmailSection = createRow();
const mail2925Section = createRow(); const mail2925Section = createRow();
@@ -300,16 +310,30 @@ const rowHotmailLocalBaseUrl = createRow();
const inputMail2925UseAccountPool = { checked: false }; const inputMail2925UseAccountPool = { checked: false };
const selectMailProvider = { value: 'icloud' }; const selectMailProvider = { value: 'icloud' };
const selectEmailGenerator = { value: 'duck', disabled: false, options: [] }; const selectEmailGenerator = { value: 'duck', disabled: false, options: [] };
const selectTempEmailDomain = { value: '' };
const selectIcloudTargetMailboxType = { value: 'icloud-inbox' }; const selectIcloudTargetMailboxType = { value: 'icloud-inbox' };
const selectIcloudForwardMailProvider = { value: 'gmail' }; const selectIcloudForwardMailProvider = { value: 'gmail' };
const selectIcloudHostPreference = { value: 'icloud.com.cn' }; const selectIcloudHostPreference = { value: 'icloud.com.cn' };
const inputTempEmailUseRandomSubdomain = { checked: false }; const inputTempEmailUseRandomSubdomain = { checked: false };
const inputTempEmailUseFixedSubdomain = { checked: false }; const inputTempEmailUseFixedSubdomain = { checked: false };
const inputTempEmailSubdomainPrefix = { value: '' }; const inputTempEmailSubdomainPrefix = {
value: '',
classList: { toggle() {} },
setAttribute() {},
};
const tempEmailSubdomainPrefixFeedback = {
textContent: '',
classList: { toggle() {} },
};
const tempEmailEffectiveDomainPreview = { textContent: '' };
const inputRunCount = { disabled: false }; const inputRunCount = { disabled: false };
const currentAutoRun = { autoRunning: false }; const currentAutoRun = { autoRunning: false };
const MAIL_PROVIDER_LOGIN_CONFIGS = { gmail: { label: 'Gmail 邮箱' } }; const MAIL_PROVIDER_LOGIN_CONFIGS = { gmail: { label: 'Gmail 邮箱' } };
const ICLOUD_FORWARD_MAIL_PROVIDER_LABELS = { gmail: 'Gmail 邮箱' }; const ICLOUD_FORWARD_MAIL_PROVIDER_LABELS = { gmail: 'Gmail 邮箱' };
const CLOUDFLARE_TEMP_EMAIL_LOOKUP_MODE_REGISTRATION_EMAIL = 'registration-email';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_NONE = 'none';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM = 'random';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED = 'fixed';
function normalizeIcloudHost(value) { return String(value || '').trim().toLowerCase(); } function normalizeIcloudHost(value) { return String(value || '').trim().toLowerCase(); }
function normalizeIcloudTargetMailboxType(value) { return String(value || '').trim().toLowerCase() === 'forward-mailbox' ? 'forward-mailbox' : 'icloud-inbox'; } function normalizeIcloudTargetMailboxType(value) { return String(value || '').trim().toLowerCase() === 'forward-mailbox' ? 'forward-mailbox' : 'icloud-inbox'; }
function normalizeIcloudForwardMailProvider(value) { return String(value || '').trim().toLowerCase() === 'gmail' ? 'gmail' : 'qq'; } function normalizeIcloudForwardMailProvider(value) { return String(value || '').trim().toLowerCase() === 'gmail' ? 'gmail' : 'qq'; }
@@ -320,6 +344,27 @@ function isIcloudMailProvider() { return selectMailProvider.value === ICLOUD_PRO
function usesCustomMailProviderPool() { return false; } function usesCustomMailProviderPool() { return false; }
function usesGeneratedAliasMailProvider() { return false; } function usesGeneratedAliasMailProvider() { return false; }
function getSelectedMail2925Mode() { return 'provide'; } function getSelectedMail2925Mode() { return 'provide'; }
function getSelectedCloudflareTempEmailLookupMode() { return 'receive-mailbox'; }
function syncCloudflareTempEmailSubdomainModeButtons() {}
function getSelectedCloudflareTempEmailSubdomainMode() {
if (inputTempEmailUseFixedSubdomain.checked) return 'fixed';
if (inputTempEmailUseRandomSubdomain.checked) return 'random';
return 'none';
}
function normalizeCloudflareTempEmailDomainValue(value = '') { return String(value || '').trim().toLowerCase(); }
function normalizeCloudflareTempEmailSubdomainPrefixValue(value = '') { return String(value || '').trim().toLowerCase(); }
function getCloudflareTempEmailSubdomainPrefixValidation(value = '') {
const raw = String(value || '').trim();
return raw
? { raw, normalized: raw.toLowerCase(), valid: true, message: '' }
: { raw, normalized: '', valid: false, message: '请填写子域前缀' };
}
function buildCloudflareTempEmailEffectiveDomainValue(domain = '', subdomainPrefix = '', options = {}) {
const normalizedDomain = normalizeCloudflareTempEmailDomainValue(domain);
const normalizedPrefix = normalizeCloudflareTempEmailSubdomainPrefixValue(subdomainPrefix);
if (options.requirePrefix && !normalizedPrefix) return '';
return normalizedPrefix && normalizedDomain ? \`\${normalizedPrefix}.\${normalizedDomain}\` : normalizedDomain;
}
function getManagedAliasProviderUiCopy() { return null; } function getManagedAliasProviderUiCopy() { return null; }
function getCurrentRegistrationEmailUiCopy() { return { buttonLabel: '获取邮箱', placeholder: '邮箱', label: '邮箱' }; } function getCurrentRegistrationEmailUiCopy() { return { buttonLabel: '获取邮箱', placeholder: '邮箱', label: '邮箱' }; }
function updateMailLoginButtonState() {} function updateMailLoginButtonState() {}
@@ -203,6 +203,13 @@ const inputTempEmailReceiveMailbox = { value: '' };
const inputTempEmailUseRandomSubdomain = { checked: false }; const inputTempEmailUseRandomSubdomain = { checked: false };
const inputTempEmailUseFixedSubdomain = { checked: false }; const inputTempEmailUseFixedSubdomain = { checked: false };
const inputTempEmailSubdomainPrefix = { value: '' }; const inputTempEmailSubdomainPrefix = { value: '' };
function getSelectedCloudflareTempEmailSubdomainMode() {
if (inputTempEmailUseFixedSubdomain.checked) return 'fixed';
if (inputTempEmailUseRandomSubdomain.checked) return 'random';
return 'none';
}
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM = 'random';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED = 'fixed';
const inputAutoSkipFailures = { checked: false }; const inputAutoSkipFailures = { checked: false };
const inputAutoSkipFailuresThreadIntervalMinutes = { value: '0' }; const inputAutoSkipFailuresThreadIntervalMinutes = { value: '0' };
const inputAutoStepDelaySeconds = { value: '' }; const inputAutoStepDelaySeconds = { value: '' };
@@ -978,6 +978,13 @@ const inputTempEmailReceiveMailbox = { value: '' };
const inputTempEmailUseRandomSubdomain = { checked: false }; const inputTempEmailUseRandomSubdomain = { checked: false };
const inputTempEmailUseFixedSubdomain = { checked: false }; const inputTempEmailUseFixedSubdomain = { checked: false };
const inputTempEmailSubdomainPrefix = { value: '' }; const inputTempEmailSubdomainPrefix = { value: '' };
function getSelectedCloudflareTempEmailSubdomainMode() {
if (inputTempEmailUseFixedSubdomain.checked) return 'fixed';
if (inputTempEmailUseRandomSubdomain.checked) return 'random';
return 'none';
}
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_RANDOM = 'random';
const CLOUDFLARE_TEMP_EMAIL_SUBDOMAIN_MODE_FIXED = 'fixed';
const inputAutoSkipFailures = { checked: false }; const inputAutoSkipFailures = { checked: false };
const inputAutoSkipFailuresThreadIntervalMinutes = { value: '0' }; const inputAutoSkipFailuresThreadIntervalMinutes = { value: '0' };
const inputAutoStepDelaySeconds = { value: '' }; const inputAutoStepDelaySeconds = { value: '' };