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

Function toggleFloatingBallTranslation

entrypoints/utils/floatingBall.ts:87–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85 * 通过键盘快捷键触发时使用
86 */
87export function toggleFloatingBallTranslation() {
88 if (!floatingBallInstance) return;
89
90 const currentState = floatingBallInstance.isTranslating;
91 const newState = !currentState;
92
93 // 触发对应的自定义事件
94 if (newState) {
95 document.dispatchEvent(new CustomEvent('fluentread-translation-started'));
96 } else {
97 document.dispatchEvent(new CustomEvent('fluentread-translation-ended'));
98 }
99
100 // 更新悬浮球状态
101 floatingBallInstance.isTranslating = newState;
102
103 // 更新UI状态 - 使用Vue实例的$el属性
104 if (floatingBallInstance.$el) {
105 if (newState) {
106 floatingBallInstance.$el.classList.add('fluent-read-floating-ball-active');
107 // 开始翻译
108 autoTranslateEnglishPage();
109 } else {
110 floatingBallInstance.$el.classList.remove('fluent-read-floating-ball-active');
111 // 恢复原文
112 restoreOriginalContent();
113 }
114 }
115}
116
117/**
118 * 处理悬浮球点击事件

Callers

nothing calls this directly

Calls 2

autoTranslateEnglishPageFunction · 0.90
restoreOriginalContentFunction · 0.90

Tested by

no test coverage detected