-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
27 lines (26 loc) · 756 Bytes
/
background.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
function updateFontList(fontData) {
chrome.storage.sync.get("fonts", function(data) {
const fonts = data.fonts || [];
const findInstances = fonts.findIndex(
(f) =>
f.font == fontData.font &&
fontData.displayHostName == f.displayHostName,
);
if (findInstances == -1) {
fontData.instances = 1;
fonts.push(fontData);
} else {
fonts[findInstances].instances += 1;
fonts[findInstances].packedAt = Date.now();
}
chrome.storage.sync.set({ fonts: fonts });
});
}
chrome.runtime.onMessage.addListener(
async function(request, sender, sendResponse) {
console.log("updating fonts");
if (request.action === "retrieveFont") {
updateFontList(request.packData);
}
},
);