()
| 42 | } |
| 43 | |
| 44 | function saveSettings() { |
| 45 | const settings = normalizeSettings({ |
| 46 | serverUrl: $("serverUrl").value, |
| 47 | apiKey: $("apiKey").value, |
| 48 | routeKey: $("routeKey").value, |
| 49 | clientLabel: $("clientLabel").value |
| 50 | }); |
| 51 | |
| 52 | if (!isValidWsUrl(settings.serverUrl)) { |
| 53 | setStatus("WebSocket URL 必须以 ws:// 或 wss:// 开头。", true); |
| 54 | return; |
| 55 | } |
| 56 | if (!settings.apiKey) { |
| 57 | setStatus("请填写 Flow2API API Key。", true); |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | chrome.storage.local.set(settings, () => { |
| 62 | if (chrome.runtime.lastError) { |
| 63 | setStatus(`保存失败:${chrome.runtime.lastError.message}`, true); |
| 64 | return; |
| 65 | } |
| 66 | setStatus("已保存,后台连接会自动重连。"); |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | document.addEventListener("DOMContentLoaded", () => { |
| 71 | loadSettings(); |
nothing calls this directly
no test coverage detected