refactor(content): simplify content script structure

- Remove messageHandler.ts (6-line pass-through facade)
- Import contextMenuHandler directly from content.ts
- Replace local getI18nText() with shared getMessage() from utils/chromeI18n

Reduces content script files from 3 to 2 and eliminates i18n logic duplication.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
雨霖铃
2026-05-29 20:10:45 +08:00
parent dff2705ef8
commit 21a6430f0d
3 changed files with 4 additions and 15 deletions
+2 -2
View File
@@ -1,10 +1,10 @@
import '../../.wxt/types/imports.d.ts';
import { initMessageHandler } from './content/messageHandler';
import { initContextMenuHandler } from './content/contextMenuHandler';
export default defineContentScript({
matches: ['<all_urls>'],
runAt: 'document_end',
main() {
initMessageHandler();
initContextMenuHandler();
},
});
@@ -1,17 +1,11 @@
import type { ContextMenuClickedPayload } from '@/utils/messages';
import { MessageAction, onMessage } from '@/utils/messages';
import { getTextStats } from '@/utils/textStatistics';
import { getMessage } from '@/utils/chromeI18n';
import { hidePopover, showTextStatsResult, showTimestampResult } from './uiPopover';
function getI18nText(key: string, fallback: string): string {
if (typeof chrome !== 'undefined' && chrome.i18n) {
return chrome.i18n.getMessage(key) || fallback;
}
return fallback;
}
function convertTimestamp(input: string): string {
const invalidText = getI18nText('invalidTimestamp', 'Invalid Timestamp');
const invalidText = getMessage('invalidTimestamp') || 'Invalid Timestamp';
const num = Number(input.trim());
if (isNaN(num)) {
@@ -1,5 +0,0 @@
import { initContextMenuHandler } from './contextMenuHandler';
export function initMessageHandler(): void {
initContextMenuHandler();
}