| 126 | |
| 127 | // 更新右键菜单状态 |
| 128 | const updateContextMenus = (tabId: number) => { |
| 129 | const isTranslated = translationStateMap.get(tabId) || false; |
| 130 | |
| 131 | try { |
| 132 | // 更新全文翻译菜单项 |
| 133 | browser.contextMenus.update(CONTEXT_MENU_IDS.TRANSLATE_FULL_PAGE, { |
| 134 | enabled: !isTranslated, |
| 135 | title: isTranslated ? '全文翻译 (已翻译)' : '全文翻译' |
| 136 | }); |
| 137 | // 更新撤销翻译菜单项 |
| 138 | browser.contextMenus.update(CONTEXT_MENU_IDS.RESTORE_ORIGINAL, { |
| 139 | enabled: isTranslated, |
| 140 | title: isTranslated ? '撤销翻译' : '撤销翻译 (无翻译)' |
| 141 | }); |
| 142 | } catch (error) { |
| 143 | console.error('Failed to update context menus:', error); |
| 144 | } |
| 145 | }; |
| 146 | |
| 147 | // 监听标签页切换事件,更新菜单状态 |
| 148 | browser.tabs.onActivated.addListener((activeInfo: any) => { |