42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
|
|
// popup.js
|
||
|
|
const defaultUrl = "https://api-inference.modelscope.cn/v1/";
|
||
|
|
const defaultModel = "Qwen/Qwen2.5-Coder-32B-Instruct";
|
||
|
|
|
||
|
|
// 初始化加载
|
||
|
|
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;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
// 保存逻辑
|
||
|
|
document.getElementById('save').addEventListener('click', () => {
|
||
|
|
const config = {
|
||
|
|
apiUrl: document.getElementById('apiUrl').value.trim(),
|
||
|
|
apiKey: document.getElementById('apiKey').value.trim(),
|
||
|
|
modelName: document.getElementById('modelName').value.trim()
|
||
|
|
};
|
||
|
|
|
||
|
|
if (!config.apiKey) {
|
||
|
|
showStatus("❌ 请输入 API Key", "#f56c6c");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
chrome.storage.sync.set({ aiConfig: config }, () => {
|
||
|
|
showStatus("✅ 配置已保存,刷新页面后生效", "#67c23a");
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
function showStatus(text, color) {
|
||
|
|
const status = document.getElementById('status');
|
||
|
|
status.textContent = text;
|
||
|
|
status.style.color = color;
|
||
|
|
setTimeout(() => { status.textContent = ''; }, 3000);
|
||
|
|
}
|