mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
(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");
|
|
}
|
|
console.log(`Removed target="_blank" from: ${element.textContent || element.innerHTML.substring(0, 50)}`);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
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"],
|
|
});
|
|
})();
|