-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
38 lines (34 loc) · 1.18 KB
/
background.js
File metadata and controls
38 lines (34 loc) · 1.18 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
chrome.runtime.onInstalled.addListener(async () => {
console.log('DisboxDownloader extension running and listening for messages');
});
function blobToBase64(blob) {
return new Promise((resolve, _) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.readAsDataURL(blob);
});
}
chrome.runtime.onMessageExternal.addListener(
function (request, sender, sendResponse) {
if (request) {
if (request.message) {
if (request.message.url) {
const urlToFetch = request.message.url;
fetch(urlToFetch)
.then(response => response.blob())
.then(blob => {
blobToBase64(blob).then(base64 => {
sendResponse({ data: base64 });
});
})
.catch(error => {
console.log(error);
});
} else {
sendResponse({ installed: true });
}
}
}
return true;
}
);