diff options
Diffstat (limited to 'extension/public')
-rw-r--r-- | extension/public/background.js | 10 | ||||
-rw-r--r-- | extension/public/iconGrabber.js | 15 | ||||
-rw-r--r-- | extension/public/manifest.json | 9 |
3 files changed, 33 insertions, 1 deletions
diff --git a/extension/public/background.js b/extension/public/background.js new file mode 100644 index 0000000..06c75eb --- /dev/null +++ b/extension/public/background.js @@ -0,0 +1,10 @@ +chrome.runtime.onMessage.addListener(async (request, sender, sendResponse) => { + console.log("received message", request) + let [url, icon] = request; + let bmk = (await chrome.bookmarks.search({url : url})); + console.log(bmk) + if (bmk && bmk.length > 0) { + await chrome.storage.local.set({["icon-"+bmk[0].id]: icon}); + } + sendResponse(); +}) diff --git a/extension/public/iconGrabber.js b/extension/public/iconGrabber.js new file mode 100644 index 0000000..63ba7e0 --- /dev/null +++ b/extension/public/iconGrabber.js @@ -0,0 +1,15 @@ +const tagTypes = ["apple-touch-icon", "shortcut icon", "icon"] + +let x = Array.from(document.getElementsByTagName("link")) + .filter(elem => tagTypes.includes(elem.rel)) + .sort((a, b) => { + let tagCompare = tagTypes.indexOf(a.rel) - tagTypes.indexOf(b.rel); + if (tagCompare !== 0) return tagCompare; + try { return Number(b.sizes[0].split('x')[0]) - Number(a.sizes[0].split('x')[0]); } + catch { return -1; } + }) + .map(elem => elem.href); + +chrome.runtime.sendMessage([window.location.href, x[0]]).catch(() => { + console.log("failed to send message") +})
\ No newline at end of file diff --git a/extension/public/manifest.json b/extension/public/manifest.json index 9f5dc51..27ba801 100644 --- a/extension/public/manifest.json +++ b/extension/public/manifest.json @@ -15,5 +15,12 @@ "permissions": [ "bookmarks", "storage" - ] + ], + "background": { + "service_worker": "background.js" + }, + "content_scripts": [{ + "js": ["iconGrabber.js"], + "matches": ["<all_urls>"] + }] } |