aboutsummaryrefslogtreecommitdiff
path: root/extension/public/iconGrabber.js
blob: c46345187e996eff6889240f2065a58a1847cade (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export function getBrowser() {
    if (typeof browser === "undefined") {
        return chrome;
    } else {
        return browser;
    }
}

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);

getBrowser().runtime.sendMessage([window.location.href, x[0]]).catch(() => {
    console.log("failed to send message")
})