-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
37 lines (34 loc) · 1.04 KB
/
background.js
File metadata and controls
37 lines (34 loc) · 1.04 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
let lastResults = [];
function scanTab(tabId) {
chrome.scripting.executeScript({
target: { tabId },
func: () => {
const regex = /https?:\/\/[a-zA-Z0-9_.\/\-?&=%#]+/g;
const pageContent = document.documentElement.outerHTML;
const matches = pageContent.match(regex) || [];
const uniqueResults = [...new Set(matches)];
uniqueResults.forEach((res) => {
chrome.runtime.sendMessage({
type: "realtime-result",
data: res
});
});
}
});
}
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.type === "scan-tab") {
lastResults = []; // reset results for fresh scan
scanTab(msg.tabId);
} else if (msg.type === "realtime-result") {
if (!lastResults.includes(msg.data)) {
lastResults.push(msg.data);
chrome.runtime.sendMessage({
type: "results-updated",
data: [msg.data]
});
}
} else if (msg.type === "get-last-results") {
sendResponse({ data: lastResults });
}
});