-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
30 lines (26 loc) · 805 Bytes
/
Copy pathbackground.js
File metadata and controls
30 lines (26 loc) · 805 Bytes
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
async function addB64(array) {
const toDataURL = url => fetch(url)
.then(response => response.blob())
.then(blob => new Promise(resolve => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.readAsDataURL(blob);
}))
.catch(error => { console.log(error) });
// populate base64 fields
let i = 1;
for (let obj of array) {
console.log(`[${i++}/${array.length}] downloading ${obj.url} as '${obj.name}.woff'`);
await toDataURL(obj.url).then(encoding => {
obj.base64 = encoding.split(',')[1];
});
}
return array;
}
// respond to message from zip() in content.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
addB64(request.array).then(updatedArray => sendResponse(updatedArray));
return true;
}
);