-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
55 lines (47 loc) · 1.69 KB
/
options.js
File metadata and controls
55 lines (47 loc) · 1.69 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* global chrome */
/**
* Debug logging function
*/
function debugLog(message, data = null) {
const timestamp = new Date().toISOString();
const logMessage = `[DearLLM Options] ${timestamp}: ${message}`;
console.log(logMessage, data || '');
}
const keyInput = document.getElementById("key");
const status = document.getElementById("status");
debugLog('Options page loaded, checking for existing API key');
chrome.storage.local.get("openai_api_key", ({ openai_api_key }) => {
if (openai_api_key) {
debugLog('Existing API key found in storage', {
keyLength: openai_api_key.length,
keyPrefix: openai_api_key.substring(0, 10) + '...'
});
keyInput.value = openai_api_key;
} else {
debugLog('No existing API key found in storage');
}
});
document.getElementById("save").addEventListener("click", () => {
const key = keyInput.value.trim();
debugLog('Save button clicked', {
keyLength: key.length,
keyPrefix: key.substring(0, 10) + '...'
});
if (!/^sk-/.test(key)) {
debugLog('Invalid API key format', { keyPrefix: key.substring(0, 10) + '...' });
status.textContent = "Looks like an invalid key.";
status.style.color = "red";
return;
}
debugLog('API key format valid, saving to storage');
chrome.storage.local.set({ openai_api_key: key }, () => {
debugLog('API key saved successfully to storage');
status.textContent = "API key saved!";
status.style.color = "green";
setTimeout(() => {
status.textContent = "";
debugLog('Status message cleared');
}, 2500);
});
});
debugLog('Options page setup complete');