-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
39 lines (27 loc) · 1.03 KB
/
content.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
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "scrape") {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const currentTab = tabs[0];
const currentUrl = currentTab.url;
sendResponse({ url: currentUrl });
});
} else if (request.action === "checkDownloadPermission") {
const userConfirmed = confirm(`The site is trying to download a file: ${request.url}. Do you want to allow this download?`);
if (userConfirmed) {
chrome.runtime.sendMessage({ action: "allowDownload", url: request.url });
} else {
console.log("Download blocked by user.");
}
}
return true;
});
window.addEventListener('load', () => {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const currentTab = tabs[0];
const currentUrl = currentTab.url;
chrome.runtime.sendMessage({
action: "scrapedURL",
url: currentUrl
});
});
});