Skip to content

refactor: normalizeMessage 抽取为共享模块#3

Open
alloevil wants to merge 1 commit into
mainfrom
refactor/normalize-message-shared
Open

refactor: normalizeMessage 抽取为共享模块#3
alloevil wants to merge 1 commit into
mainfrom
refactor/normalize-message-shared

Conversation

@alloevil

@alloevil alloevil commented Jul 8, 2026

Copy link
Copy Markdown
Owner

问题

auto-archive-simple.js 中有两个 normalizeMessage 函数

  • 浏览器端注入脚本(USER_SCRIPT 内,~80 行)
  • Node.js 端 HTTP 分页(~100 行)

逻辑几乎相同但有细微差异(如 p.large?.url 只在 Node 端有),修改一处忘改另一处就会出 bug。

修复

  • ✅ 新建 lib/normalize-message.js,作为 Node.js 端唯一入口
  • auto-archive-simple.js 删除内联副本,改为 require
  • ✅ 浏览器端 USER_SCRIPT 保留(浏览器上下文无法 require)
  • ✅ 零行为变更,纯提取重构

为什么浏览器端不一起改

USER_SCRIPT 是注入到 Puppeteer 页面的字符串,无法 require() CJS 模块。如果未来要完全统一,需要用 bundler 打包或把模块源码内联为字符串——复杂度不值得当前收益。

- New module: lib/normalize-message.js (single source of truth)
- auto-archive-simple.js: remove inline Node.js-side duplicate, use shared module
- Browser-side USER_SCRIPT copy retained (can't require() in browser context)
- Zero behavior change, pure extraction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant