From be4bbe55df1e57e4ec0837d998c6c083a47f0982 Mon Sep 17 00:00:00 2001
From: Cx330 <1487537121@qq.com>
Date: Sun, 11 Jan 2026 17:35:50 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=9B=AE=E5=89=8D=E5=B7=B2?=
=?UTF-8?q?=E7=9F=A5Bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
popup.html | 14 ++++++++------
popup.js | 35 +++++++++++++++++++----------------
2 files changed, 27 insertions(+), 22 deletions(-)
diff --git a/popup.html b/popup.html
index 52304e6..f44c0b3 100644
--- a/popup.html
+++ b/popup.html
@@ -12,24 +12,26 @@
.btn { background: #409eff; color: white; border: none; padding: 10px; border-radius: 4px; cursor: pointer; width: 100%; font-weight: bold; margin-top: 5px; }
.btn:hover { background: #66b1ff; }
#status { font-size: 12px; text-align: center; margin-top: 8px; height: 14px; }
+ .note { font-size: 11px; color: #999; margin-top: 4px; }
- AI 模型配置
+ ⚙️ AI 模型配置
-
-
+
+
-
-
+
+
diff --git a/popup.js b/popup.js
index 6aa5145..41b85bf 100644
--- a/popup.js
+++ b/popup.js
@@ -1,42 +1,45 @@
-// popup.js
-const defaultUrl = "https://api-inference.modelscope.cn/v1/";
-const defaultModel = "Qwen/Qwen2.5-Coder-32B-Instruct";
+// 设置默认值
+const DEFAULT_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1";
+const DEFAULT_MODEL = "qwen-plus";
-// 初始化加载
+// 页面加载时读取存储的配置
document.addEventListener('DOMContentLoaded', () => {
chrome.storage.sync.get(['aiConfig'], (result) => {
- if (result.aiConfig) {
- document.getElementById('apiUrl').value = result.aiConfig.apiUrl || defaultUrl;
- document.getElementById('apiKey').value = result.aiConfig.apiKey || "";
- document.getElementById('modelName').value = result.aiConfig.modelName || defaultModel;
- } else {
- document.getElementById('apiUrl').value = defaultUrl;
- document.getElementById('modelName').value = defaultModel;
- }
+ const config = result.aiConfig || {};
+
+ // 如果没有存储的值,则显示默认占位符或默认值
+ document.getElementById('apiUrl').value = config.apiUrl || DEFAULT_URL;
+ document.getElementById('apiKey').value = config.apiKey || "";
+ document.getElementById('modelName').value = config.modelName || DEFAULT_MODEL;
});
});
// 保存逻辑
document.getElementById('save').addEventListener('click', () => {
const config = {
- apiUrl: document.getElementById('apiUrl').value.trim(),
+ apiUrl: document.getElementById('apiUrl').value.trim() || DEFAULT_URL,
apiKey: document.getElementById('apiKey').value.trim(),
- modelName: document.getElementById('modelName').value.trim()
+ modelName: document.getElementById('modelName').value.trim() || DEFAULT_MODEL
};
+ // 验证 API Key 是否填写
if (!config.apiKey) {
showStatus("❌ 请输入 API Key", "#f56c6c");
return;
}
+ // 存储到 chrome.storage
chrome.storage.sync.set({ aiConfig: config }, () => {
- showStatus("✅ 配置已保存,刷新页面后生效", "#67c23a");
+ showStatus("✅ 配置已保存,刷新页面生效", "#67c23a");
});
});
+// 状态提示函数
function showStatus(text, color) {
const status = document.getElementById('status');
status.textContent = text;
status.style.color = color;
- setTimeout(() => { status.textContent = ''; }, 3000);
+ setTimeout(() => {
+ status.textContent = '';
+ }, 3000);
}
\ No newline at end of file