()
| 1687 | |
| 1688 | // 初始化程序 |
| 1689 | function initApplication() { |
| 1690 | // 判断是否需要清除当前页面的缓存 |
| 1691 | localStorageManager.clearLocalStorageIfNewSession() |
| 1692 | // 初始化菜单栏配置 |
| 1693 | let commonConfig = [ |
| 1694 | {name: 'hotkey', value: 'Control'}, |
| 1695 | {name: 'from', value: 'auto'}, |
| 1696 | {name: 'to', value: 'zh-Hans'}, |
| 1697 | {name: 'model', value: transModel.microsoft} |
| 1698 | ] |
| 1699 | let modelConfig = [ |
| 1700 | {openai: "gpt-3.5-turbo"}, |
| 1701 | {yiyan: "completions"}, |
| 1702 | {tongyi: "qwen-turbo"}, |
| 1703 | {zhipu: "glm-3-turbo"}, |
| 1704 | {moonshot: "moonshot-v1-8"}, |
| 1705 | {gemini: "gemini-pro"}, |
| 1706 | ] |
| 1707 | commonConfig.forEach(v => !util.getValue(v.name) ? util.setValue(v.name, v.value) : null); |
| 1708 | modelConfig.forEach(option => { |
| 1709 | let key = Object.keys(option)[0]; // 获取对象的第一个键 |
| 1710 | let value = option[key]; // 使用该键获取值 |
| 1711 | if (!optionsManager.getOption(key)) optionsManager.setOption(key, value); |
| 1712 | }); |
| 1713 | setShortcut(util.getValue('hotkey')); // 快捷键设置 |
| 1714 | |
| 1715 | // 初始化菜单 |
| 1716 | GM_registerMenuCommand(`原始语言:${langManager.from[util.getValue('from')]}`, () => settingManager.setLanguage('from')); |
| 1717 | GM_registerMenuCommand(`目标语言:${langManager.to[util.getValue('to')]}`, () => settingManager.setLanguage('to')); |
| 1718 | GM_registerMenuCommand(`鼠标快捷键:${shortcutManager.hotkeyOptions[util.getValue('hotkey')]}`, () => settingManager.setHotkey()); |
| 1719 | GM_registerMenuCommand(`翻译服务:${transModelName[util.getValue('model')]}`, () => settingManager.setSetting()); |
| 1720 | GM_registerMenuCommand('检查更新', () => settingManager.update()); |
| 1721 | GM_registerMenuCommand('关于项目', () => settingManager.about()); |
| 1722 | |
| 1723 | // 初始化翻译模型对应函数 |
| 1724 | transModelFn[transModel.microsoft] = microsoft |
| 1725 | transModelFn[transModel.deepL] = deepL |
| 1726 | |
| 1727 | transModelFn[transModel.openai] = openai |
| 1728 | transModelFn[transModel.yiyan] = yiyan |
| 1729 | transModelFn[transModel.tongyi] = tongyi |
| 1730 | transModelFn[transModel.zhipu] = zhipu |
| 1731 | transModelFn[transModel.moonshot] = moonshot |
| 1732 | transModelFn[transModel.gemini] = gemini |
| 1733 | |
| 1734 | transModelFn[transModel.ollama] = ollama |
| 1735 | |
| 1736 | // 填充适配器 map |
| 1737 | adapterFnMap[exceptionMap.maven] = procMaven |
| 1738 | adapterFnMap[exceptionMap.docker] = procDockerhub |
| 1739 | adapterFnMap[exceptionMap.openai_web] = procOpenai |
| 1740 | adapterFnMap[exceptionMap.coze] = procCoze |
| 1741 | // 填充 skip map |
| 1742 | skipStringMap[exceptionMap.openai_web] = function (node) { |
| 1743 | return node.hasAttribute("data-message-author-role") || node.hasAttribute("data-projection-id") |
| 1744 | } |
| 1745 | skipStringMap[exceptionMap.nexusmods] = function (node) { |
| 1746 | return node.classList.contains("desc") || node.classList.contains("material-icons") || node.classList.contains("material-icons-outlined") |
no test coverage detected