Repository navigation
Expand file tree
/
Copy pathoptions.js
More file actions
46 lines (42 loc) · 1.62 KB
/
Copy pathoptions.js
File metadata and controls
46 lines (42 loc) · 1.62 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
document.addEventListener('DOMContentLoaded', () => {
const apiKeyInput = document.getElementById('api-key');
const saveButton = document.getElementById('save-btn');
const statusDiv = document.getElementById('status');
const toggleContainer = document.getElementById('toggle-container');
const showKeyToggle = document.getElementById('show-key-toggle');
function setStatus(message, isError = false) {
statusDiv.textContent = message;
statusDiv.style.color = isError ? 'red' : 'green';
}
chrome.storage.sync.get('hfApiKey', (data) => {
if (data.hfApiKey) {
apiKeyInput.value = data.hfApiKey;
toggleContainer.style.display = 'flex';
}
});
saveButton.addEventListener('click', () => {
const apiKey = apiKeyInput.value.trim();
if (apiKey) {
chrome.storage.sync.set({ hfApiKey: apiKey }, () => {
if (chrome.runtime.lastError) {
setStatus(`Error saving key: ${chrome.runtime.lastError.message}`, true);
} else {
setStatus('API Key saved successfully!', false);
toggleContainer.style.display = 'flex';
setTimeout(() => {
setStatus('');
}, 3000);
}
});
} else {
setStatus('Please enter an API key.', true);
}
});
showKeyToggle.addEventListener('change', () => {
if (showKeyToggle.checked) {
apiKeyInput.type = 'text';
} else {
apiKeyInput.type = 'password';
}
});
});