From a273bc2c4b4962f04c454da44b47bcd2fb371e30 Mon Sep 17 00:00:00 2001 From: Ryan Liu Date: Sat, 25 Apr 2026 11:49:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E7=BD=91=E6=98=93?= =?UTF-8?q?=E9=82=AE=E7=AE=B1=E5=85=B1=E4=BA=AB=E8=84=9A=E6=9C=AC=E7=9A=84?= =?UTF-8?q?=E9=82=AE=E7=AE=B1=E5=93=81=E7=89=8C=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/mail-163.js | 24 ++++++++++++++++++++---- tests/mail-163-content.test.js | 24 +++++++++++++++++++++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/content/mail-163.js b/content/mail-163.js index f31608a..3756a87 100644 --- a/content/mail-163.js +++ b/content/mail-163.js @@ -73,6 +73,21 @@ function normalizeText(value) { return String(value || '').replace(/\s+/g, ' ').trim(); } +function getNetEaseMailLabel(hostname) { + const currentHostname = String( + hostname || (typeof location !== 'undefined' ? location.hostname : '') || '' + ).toLowerCase(); + + if (currentHostname === 'mail.126.com' || currentHostname.endsWith('.mail.126.com')) { + return '126 邮箱'; + } + if (currentHostname === 'webmail.vip.163.com') { + return '163 VIP 邮箱'; + } + + return '163 邮箱'; +} + function isVisibleNode(node) { if (!node) return false; if (node.hidden) return false; @@ -476,8 +491,9 @@ async function handlePollEmail(step, payload) { const { senderFilters, subjectFilters, maxAttempts, intervalMs, excludeCodes = [], filterAfterTimestamp = 0 } = payload; const excludedCodeSet = new Set(excludeCodes.filter(Boolean)); const filterAfterMinute = normalizeMinuteTimestamp(Number(filterAfterTimestamp) || 0); + const mailLabel = getNetEaseMailLabel(); - log(`步骤 ${step}:开始轮询 163 邮箱(最多 ${maxAttempts} 次)`); + log(`步骤 ${step}:开始轮询 ${mailLabel}(最多 ${maxAttempts} 次)`); if (filterAfterMinute) { log(`步骤 ${step}:仅尝试 ${new Date(filterAfterMinute).toLocaleString('zh-CN', { hour12: false })} 及之后时间的邮件。`); } @@ -508,7 +524,7 @@ async function handlePollEmail(step, payload) { } if (items.length === 0) { - throw new Error('163 邮箱列表未加载完成,请确认当前已打开收件箱。'); + throw new Error(`${mailLabel}列表未加载完成,请确认当前已打开收件箱。`); } log(`步骤 ${step}:邮件列表已加载,共 ${items.length} 封邮件`); @@ -520,7 +536,7 @@ async function handlePollEmail(step, payload) { const FALLBACK_AFTER = 3; for (let attempt = 1; attempt <= maxAttempts; attempt++) { - log(`步骤 ${step}:正在轮询 163 邮箱,第 ${attempt}/${maxAttempts} 次`); + log(`步骤 ${step}:正在轮询 ${mailLabel},第 ${attempt}/${maxAttempts} 次`); if (attempt > 1) { await refreshInbox(); @@ -605,7 +621,7 @@ async function handlePollEmail(step, payload) { } throw new Error( - `${(maxAttempts * intervalMs / 1000).toFixed(0)} 秒后仍未在 163 邮箱中找到新的匹配邮件。` + + `${(maxAttempts * intervalMs / 1000).toFixed(0)} 秒后仍未在 ${mailLabel}中找到新的匹配邮件。` + '请手动检查收件箱。' ); } diff --git a/tests/mail-163-content.test.js b/tests/mail-163-content.test.js index e3be17d..8d8f384 100644 --- a/tests/mail-163-content.test.js +++ b/tests/mail-163-content.test.js @@ -101,6 +101,23 @@ return { findMailItems }; assert.equal(rows.length, 1); }); +test('getNetEaseMailLabel returns the active NetEase mailbox brand', () => { + const bundle = [ + extractFunction('getNetEaseMailLabel'), + ].join('\n'); + + const api = new Function(` +${bundle} +return { getNetEaseMailLabel }; +`)(); + + assert.equal(api.getNetEaseMailLabel('mail.126.com'), '126 邮箱'); + assert.equal(api.getNetEaseMailLabel('app.mail.126.com'), '126 邮箱'); + assert.equal(api.getNetEaseMailLabel('webmail.vip.163.com'), '163 VIP 邮箱'); + assert.equal(api.getNetEaseMailLabel('mail.163.com'), '163 邮箱'); + assert.equal(api.getNetEaseMailLabel('example.com'), '163 邮箱'); +}); + test('getMailTimestamp parses visible hh:mm text even when no title attribute exists', () => { const bundle = [ extractFunction('normalizeText'), @@ -358,10 +375,12 @@ test('handlePollEmail ignores same-minute old snapshot mail before fallback', as const bundle = [ extractFunction('normalizeText'), extractFunction('normalizeMinuteTimestamp'), + extractFunction('getNetEaseMailLabel'), extractFunction('handlePollEmail'), ].join('\n'); const api = new Function(` +const location = { hostname: 'mail.126.com' }; let currentItems = [{ id: 'old-mail' }]; const seenCodes = new Set(); @@ -419,7 +438,7 @@ return { handlePollEmail }; intervalMs: 1, filterAfterTimestamp: new Date(2026, 3, 22, 22, 22, 40, 0).getTime(), }), - /未在 163 邮箱中找到新的匹配邮件/ + /未在 126 邮箱中找到新的匹配邮件/ ); }); @@ -427,6 +446,7 @@ test('handlePollEmail accepts a new same-minute mail that appears after the snap const bundle = [ extractFunction('normalizeText'), extractFunction('normalizeMinuteTimestamp'), + extractFunction('getNetEaseMailLabel'), extractFunction('handlePollEmail'), ].join('\n'); @@ -519,6 +539,7 @@ test('handlePollEmail falls back to row text when the subject node is missing', const bundle = [ extractFunction('normalizeText'), extractFunction('normalizeMinuteTimestamp'), + extractFunction('getNetEaseMailLabel'), extractFunction('handlePollEmail'), ].join('\n'); @@ -598,6 +619,7 @@ test('handlePollEmail opens matching mail body when preview has no code', async const bundle = [ extractFunction('normalizeText'), extractFunction('normalizeMinuteTimestamp'), + extractFunction('getNetEaseMailLabel'), extractFunction('handlePollEmail'), ].join('\n');