修复目前已知Bug

This commit is contained in:
张梦南 2026-01-11 17:35:50 +08:00
parent ea1cfd0fa7
commit be4bbe55df
2 changed files with 27 additions and 22 deletions

View File

@ -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 { 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; } .btn:hover { background: #66b1ff; }
#status { font-size: 12px; text-align: center; margin-top: 8px; height: 14px; } #status { font-size: 12px; text-align: center; margin-top: 8px; height: 14px; }
.note { font-size: 11px; color: #999; margin-top: 4px; }
</style> </style>
</head> </head>
<body> <body>
<h3>AI 模型配置</h3> <h3>⚙️ AI 模型配置</h3>
<div class="item"> <div class="item">
<label>API Base URL</label> <label>API Base URL</label>
<input type="text" id="apiUrl" placeholder="https://api-inference.modelscope.cn/v1/"> <input type="text" id="apiUrl" placeholder="https://api-inference.modelscope.cn/v1">
<div class="note">通常使用兼容模式地址</div>
</div> </div>
<div class="item"> <div class="item">
<label>Access Token (API Key)</label> <label>API Key</label>
<input type="password" id="apiKey" placeholder="输入您的 Token"> <input type="password" id="apiKey" placeholder="sk-...">
</div> </div>
<div class="item"> <div class="item">
<label>Model ID</label> <label>Model Name</label>
<input type="text" id="modelName" placeholder="Qwen/Qwen2.5-Coder-32B-Instruct"> <input type="text" id="modelName" placeholder="deepseek-ai/DeepSeek-V3.2">
</div> </div>
<button id="save" class="btn">保存并生效</button> <button id="save" class="btn">保存并生效</button>

View File

@ -1,42 +1,45 @@
// popup.js // 设置默认值
const defaultUrl = "https://api-inference.modelscope.cn/v1/"; const DEFAULT_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1";
const defaultModel = "Qwen/Qwen2.5-Coder-32B-Instruct"; const DEFAULT_MODEL = "qwen-plus";
// 初始化加载 // 页面加载时读取存储的配置
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
chrome.storage.sync.get(['aiConfig'], (result) => { chrome.storage.sync.get(['aiConfig'], (result) => {
if (result.aiConfig) { const config = 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; document.getElementById('apiUrl').value = config.apiUrl || DEFAULT_URL;
} else { document.getElementById('apiKey').value = config.apiKey || "";
document.getElementById('apiUrl').value = defaultUrl; document.getElementById('modelName').value = config.modelName || DEFAULT_MODEL;
document.getElementById('modelName').value = defaultModel;
}
}); });
}); });
// 保存逻辑 // 保存逻辑
document.getElementById('save').addEventListener('click', () => { document.getElementById('save').addEventListener('click', () => {
const config = { const config = {
apiUrl: document.getElementById('apiUrl').value.trim(), apiUrl: document.getElementById('apiUrl').value.trim() || DEFAULT_URL,
apiKey: document.getElementById('apiKey').value.trim(), 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) { if (!config.apiKey) {
showStatus("❌ 请输入 API Key", "#f56c6c"); showStatus("❌ 请输入 API Key", "#f56c6c");
return; return;
} }
// 存储到 chrome.storage
chrome.storage.sync.set({ aiConfig: config }, () => { chrome.storage.sync.set({ aiConfig: config }, () => {
showStatus("✅ 配置已保存,刷新页面生效", "#67c23a"); showStatus("✅ 配置已保存,刷新页面生效", "#67c23a");
}); });
}); });
// 状态提示函数
function showStatus(text, color) { function showStatus(text, color) {
const status = document.getElementById('status'); const status = document.getElementById('status');
status.textContent = text; status.textContent = text;
status.style.color = color; status.style.color = color;
setTimeout(() => { status.textContent = ''; }, 3000); setTimeout(() => {
status.textContent = '';
}, 3000);
} }