MCPcopy
hub / github.com/Bistutu/FluentRead / main

Function main

entrypoints/content.ts:17–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15 matches: ['<all_urls>'], // 匹配所有页面
16 runAt: 'document_end', // 在页面加载完成后运行
17 async main() {
18 await configReady // 等待配置加载完成
19 if (config.on === false) return; // 如果配置关闭,则不执行任何操作
20 // 添加手动翻译事件监听器
21 setupManualTranslationTriggers();
22 // 添加悬浮球快捷键事件监听器
23 setupFloatingBallHotkey();
24 // 当悬浮球关闭时,仍然允许使用快捷键进行全文翻译的独立开关
25 let isFullPageTranslating = false;
26 document.addEventListener('fluentread-toggle-translation', () => {
27 // 仅在悬浮球被禁用(未挂载)时由内容脚本接管快捷键
28 if (config.disableFloatingBall === true) {
29 isFullPageTranslating = !isFullPageTranslating;
30 if (isFullPageTranslating) {
31 autoTranslateEnglishPage();
32 } else {
33 restoreOriginalContent();
34 }
35 }
36 });
37 // 添加自动翻译事件监听器
38 if (config.autoTranslate) autoTranslationEvent();
39
40 // 挂载悬浮球(如果配置未禁用)
41 if (config.disableFloatingBall !== true) {
42 // 使用配置中的位置
43 mountFloatingBall();
44 }
45
46 // 挂载划词翻译组件(如果配置未禁用)
47 if (config.disableSelectionTranslator !== true) {
48 mountSelectionTranslator();
49 }
50
51 // 挂载翻译状态组件(可配置禁用)
52 if (config.translationStatus === true) {
53 mountTranslationStatusComponent();
54 }
55
56 mountNewApiComponent();
57
58 cache.cleaner(); // 检测是否清理缓存
59
60 // background.ts
61 browser.runtime.onMessage.addListener((message: { message: string; }, sender: any, sendResponse: () => void) => {
62 if (message.message === 'clearCache') cache.clean()
63 sendResponse();
64 return true;
65 });
66
67 // 处理悬浮球控制消息
68 browser.runtime.onMessage.addListener((message: any, sender: any, sendResponse: () => void) => {
69 if (message.type === 'toggleFloatingBall') {
70 if (message.isEnabled) {
71 mountFloatingBall();
72 } else {
73 unmountFloatingBall();
74 }

Callers

nothing calls this directly

Calls 12

autoTranslateEnglishPageFunction · 0.90
restoreOriginalContentFunction · 0.90
mountFloatingBallFunction · 0.90
mountSelectionTranslatorFunction · 0.90
mountNewApiComponentFunction · 0.90
unmountFloatingBallFunction · 0.90
cancelAllTranslationsFunction · 0.90
setupFloatingBallHotkeyFunction · 0.85
autoTranslationEventFunction · 0.85

Tested by

no test coverage detected