* 专门用于输入框翻译的微软翻译函数(不使用缓存) * 通过background脚本调用,避免Firefox的CORS问题
(text: string, targetLang: string)
| 922 | * 通过background脚本调用,避免Firefox的CORS问题 |
| 923 | */ |
| 924 | async function translateWithMicrosoft(text: string, targetLang: string): Promise<string> { |
| 925 | try { |
| 926 | // 发送消息给background脚本进行翻译 |
| 927 | const result = await browser.runtime.sendMessage({ |
| 928 | type: 'inputBoxTranslation', |
| 929 | text: text, |
| 930 | targetLang: targetLang |
| 931 | }); |
| 932 | |
| 933 | if (result && result.success) { |
| 934 | return result.translatedText; |
| 935 | } else { |
| 936 | throw new Error(result?.error || '微软翻译失败'); |
| 937 | } |
| 938 | } catch (error) { |
| 939 | console.error('微软翻译请求失败:', error); |
| 940 | throw error; |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | /** |
| 945 | * 处理输入框翻译 |
no outgoing calls
no test coverage detected