-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebicon.js
30 lines (27 loc) · 1.03 KB
/
webicon.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
28
29
30
const DARK_OVERRIDE = {
"github.com": "https://github.githubassets.com/favicons/favicon-dark.svg",
};
// Don't do icons on localhost because:
// a) spams a lot of requests to the API
// b) CORS is annoying and I don't want to deal with it
if (window.location.hostname !== "localhost") {
for (const extLink of document.querySelectorAll(
'a[data-external-link="true"]',
)) {
try {
const url = new URL(extLink.getAttribute("href"));
if (url.hostname in DARK_OVERRIDE) {
extLink.style.setProperty(
"--webicon-dark",
`url("${DARK_OVERRIDE[url.hostname]}")`,
);
}
const iconUrl = `https://webicon.ariscript.org/${encodeURIComponent(url.toString())}`;
fetch(iconUrl).then(
(r) =>
r.status === 200 &&
extLink.style.setProperty("--webicon", `url("${iconUrl}")`),
);
} catch {} // if the href is not valid, do nothing
}
}