-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.js
More file actions
42 lines (36 loc) · 1.25 KB
/
options.js
File metadata and controls
42 lines (36 loc) · 1.25 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
document.addEventListener('DOMContentLoaded', () => {
chrome.storage.sync.get(['vtApiKey'], (result) => {
if (result.vtApiKey) {
document.getElementById('apiKey').value = result.vtApiKey;
}
});
});
document.getElementById('saveBtn').addEventListener('click', () => {
const apiKey = document.getElementById('apiKey').value.trim();
const statusDiv = document.getElementById('status');
if (!apiKey) {
statusDiv.textContent = 'Please enter an API key';
statusDiv.className = 'status error';
statusDiv.style.display = 'block';
return;
}
if (apiKey.length !== 64) {
statusDiv.textContent = 'Invalid API key format. VirusTotal API keys are 64 characters long.';
statusDiv.className = 'status error';
statusDiv.style.display = 'block';
return;
}
chrome.storage.sync.set({ vtApiKey: apiKey }, () => {
statusDiv.textContent = 'API key saved successfully! You can now use the extension.';
statusDiv.className = 'status success';
statusDiv.style.display = 'block';
setTimeout(() => {
statusDiv.style.display = 'none';
}, 3000);
});
});
document.getElementById('apiKey').addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
document.getElementById('saveBtn').click();
}
});