-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
53 lines (46 loc) · 1.83 KB
/
popup.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
42
43
44
45
46
47
48
49
50
51
52
53
document.addEventListener('DOMContentLoaded', () => {
const statusElement = document.getElementById('status');
document.getElementById('startButton').addEventListener('click', async () => {
// Get IDs from the textarea
let ids = document.getElementById('idList').value;
// Split IDs by commas or new lines and remove empty entries
ids = ids.split(/[\s,]+/).filter(id => id.trim() !== '');
if (ids.length === 0) {
alert('Please enter at least one ID.');
return;
}
// Get the active tab
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
// Inject the content script and jQuery into the active tab
try {
// Inject jQuery
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['jquery.js']
});
// Inject content script
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ['contentScript.js']
});
// Send IDs to the content script
chrome.tabs.sendMessage(tab.id, { action: 'startDeleting', ids: ids }, response => {
if (chrome.runtime.lastError) {
statusElement.textContent = 'Error: ' + chrome.runtime.lastError.message;
} else {
statusElement.textContent = `Deletion started. Remaining IDs: ${ids.length}`;
}
});
} catch (error) {
statusElement.textContent = 'Error injecting scripts: ' + error;
}
});
// Listen for progress updates from the background script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'updateProgress') {
statusElement.textContent = `Remaining IDs: ${message.remaining}`;
} else if (message.action === 'deletionCompleted') {
statusElement.textContent = 'All IDs have been processed.';
}
});
});