fix: 修正网易邮箱共享脚本的邮箱品牌日志
This commit is contained in:
+20
-4
@@ -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}中找到新的匹配邮件。` +
|
||||
'请手动检查收件箱。'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user