-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.js
41 lines (34 loc) · 1.17 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
document.addEventListener('DOMContentLoaded', function() {
const apiKeyInput = document.getElementById('apiKey');
const saveButton = document.getElementById('saveButton');
const statusDiv = document.getElementById('status');
// Mevcut API anahtarını yükle
chrome.storage.local.get(['openaiApiKey'], function(result) {
if (result.openaiApiKey) {
apiKeyInput.value = result.openaiApiKey;
}
});
// API anahtarını kaydet
saveButton.addEventListener('click', function() {
const apiKey = apiKeyInput.value.trim();
if (!apiKey) {
showStatus('API anahtarı boş olamaz!', false);
return;
}
if (!apiKey.startsWith('sk-')) {
showStatus('Geçersiz API anahtarı formatı!', false);
return;
}
chrome.storage.local.set({ openaiApiKey: apiKey }, function() {
showStatus('API anahtarı başarıyla kaydedildi!', true);
});
});
function showStatus(message, success) {
statusDiv.textContent = message;
statusDiv.className = 'status ' + (success ? 'success' : 'error');
statusDiv.style.display = 'block';
setTimeout(function() {
statusDiv.style.display = 'none';
}, 3000);
}
});