-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
119 lines (102 loc) · 3.74 KB
/
popup.js
File metadata and controls
119 lines (102 loc) · 3.74 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
document.addEventListener('DOMContentLoaded', () => {
const hashInput = document.getElementById('hashInput');
const fetchBtn = document.getElementById('fetchBtn');
const clearBtn = document.getElementById('clearBtn');
const statusDiv = document.getElementById('status');
const settingsLink = document.getElementById('settingsLink');
// Check if API key is set
chrome.storage.sync.get(['vtApiKey'], (result) => {
if (!result.vtApiKey) {
statusDiv.textContent = '⚠️ Please set your API key in settings first!';
statusDiv.className = 'status error';
fetchBtn.disabled = true;
}
});
// Settings link
settingsLink.addEventListener('click', (e) => {
e.preventDefault();
chrome.runtime.openOptionsPage();
});
// Clear button
clearBtn.addEventListener('click', () => {
hashInput.value = '';
statusDiv.style.display = 'none';
hashInput.focus();
});
// Fetch button
fetchBtn.addEventListener('click', async () => {
const input = hashInput.value.trim();
if (!input) {
statusDiv.textContent = 'Please enter at least one hash';
statusDiv.className = 'status error';
return;
}
// Parse hashes from input (split by newlines, commas, or spaces)
const hashes = input
.split(/[\n,\s]+/)
.map(h => h.trim())
.filter(h => h.length > 0);
if (hashes.length === 0) {
statusDiv.textContent = 'No valid hashes found';
statusDiv.className = 'status error';
return;
}
// Validate hashes
const md5Regex = /^[a-fA-F0-9]{32}$/;
const sha1Regex = /^[a-fA-F0-9]{40}$/;
const sha256Regex = /^[a-fA-F0-9]{64}$/;
const validHashes = [];
const invalidHashes = [];
hashes.forEach(hash => {
if (md5Regex.test(hash) || sha1Regex.test(hash) || sha256Regex.test(hash)) {
validHashes.push(hash);
} else {
invalidHashes.push(hash);
}
});
if (validHashes.length === 0) {
statusDiv.textContent = 'No valid hashes found. Please enter MD5, SHA-1, or SHA-256 hashes.';
statusDiv.className = 'status error';
return;
}
const uniqueValid = Array.from(new Set(validHashes.map(h => h.toLowerCase())));
const dedupCount = validHashes.length - uniqueValid.length;
if (invalidHashes.length > 0 || dedupCount > 0) {
const parts = [];
if (invalidHashes.length > 0) parts.push(`${invalidHashes.length} invalid`);
if (dedupCount > 0) parts.push(`${dedupCount} duplicate`);
statusDiv.textContent = `Warning: ${parts.join(' + ')} hash(es) skipped. Processing ${uniqueValid.length} valid unique hash(es)...`;
statusDiv.className = 'status info';
} else {
statusDiv.textContent = `Processing ${uniqueValid.length} hash(es)...`;
statusDiv.className = 'status info';
}
fetchBtn.disabled = true;
fetchBtn.textContent = 'Fetching...';
// Send message to background script to fetch all hashes
chrome.runtime.sendMessage(
{ action: 'fetchMultipleHashes', hashes: uniqueValid },
(response) => {
fetchBtn.disabled = false;
fetchBtn.textContent = 'Fetch All Hashes';
if (response && response.success) {
statusDiv.textContent = `✓ Opening results in new tab...`;
statusDiv.className = 'status success';
// Close popup after a short delay
setTimeout(() => {
window.close();
}, 1000);
} else {
statusDiv.textContent = `Error: ${response?.error || 'Unknown error occurred'}`;
statusDiv.className = 'status error';
}
}
);
});
// Allow Ctrl+Enter to fetch
hashInput.addEventListener('keydown', (e) => {
if (e.ctrlKey && e.key === 'Enter') {
fetchBtn.click();
}
});
});