feat: 增强邮箱获取功能,自动尝试获取 DuckDuckGo 邮箱并提供手动粘贴提示

This commit is contained in:
QLHazyCoder
2026-04-08 01:42:35 +08:00
parent 96867783dd
commit 099066987d
2 changed files with 15 additions and 6 deletions
+12 -5
View File
@@ -268,7 +268,8 @@ function escapeHtml(text) {
return div.innerHTML;
}
async function fetchDuckEmail() {
async function fetchDuckEmail(options = {}) {
const { showFailureToast = true } = options;
const defaultLabel = '获取';
btnFetchEmail.disabled = true;
btnFetchEmail.textContent = '...';
@@ -291,7 +292,9 @@ async function fetchDuckEmail() {
showToast(`已获取 ${response.email}`, 'success', 2500);
return response.email;
} catch (err) {
showToast(`自动获取失败:${err.message}`, 'error');
if (showFailureToast) {
showToast(`自动获取失败:${err.message}`, 'error');
}
throw err;
} finally {
btnFetchEmail.disabled = false;
@@ -311,10 +314,14 @@ document.querySelectorAll('.step-btn').forEach(btn => {
btn.addEventListener('click', async () => {
const step = Number(btn.dataset.step);
if (step === 3) {
const email = inputEmail.value.trim();
let email = inputEmail.value.trim();
if (!email) {
showToast('请先粘贴邮箱,或先点击获取。', 'warn');
return;
try {
email = await fetchDuckEmail({ showFailureToast: false });
} catch (err) {
showToast(`自动获取失败:${err.message},请手动粘贴邮箱后重试。`, 'warn');
return;
}
}
await chrome.runtime.sendMessage({ type: 'EXECUTE_STEP', source: 'sidepanel', payload: { step, email } });
} else {