forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize-internal-links.js
More file actions
43 lines (39 loc) · 1.21 KB
/
normalize-internal-links.js
File metadata and controls
43 lines (39 loc) · 1.21 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
(function () {
function normalizeInternalLinks() {
const selectors = [
'a[href*="bun.com/docs/installation"]',
'a[href="https://bun.com/reference"]',
'a[href="https://bun.com/blog"]',
];
selectors.forEach(selector => {
const elements = document.querySelectorAll(selector);
elements.forEach(element => {
if (element.hasAttribute("target")) {
element.removeAttribute("target");
// Also remove rel="noreferrer" if present, typically paired with target="_blank"
if (element.getAttribute("rel") === "noreferrer") {
element.removeAttribute("rel");
}
}
});
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", normalizeInternalLinks);
} else {
normalizeInternalLinks();
}
const observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.type === "childList" || mutation.type === "attributes") {
normalizeInternalLinks();
}
});
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ["target", "href"],
});
})();