blob: b02e3150f1cbe3cfca626b426730c96e897a82f9 (
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
24
25
26
27
28
29
30
31
|
function getBrowser() {
return typeof browser === "undefined" ? chrome : 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) => {
function compareTags() {
// ascending
return tagTypes.indexOf(a.rel) - tagTypes.indexOf(b.rel);
}
function compareSizes() {
function getSize(elem) {
try { return Number(elem.sizes[0].split('x')[0]); }
catch { return 0; }
}
// descending
return getSize(b) - getSize(a);
}
return compareSizes() || compareTags()
});
console.log("found icons", x.map(elem => elem.outerHTML));
x = x.map(elem => elem.href);
getBrowser().runtime.sendMessage([window.location.href, x[0]]).catch(() => {
console.log("failed to send message")
})
|