MediaWiki:Vector.js: Difference between revisions
Jump to navigation
Jump to search
Created page with "→All JavaScript here will be loaded for users of the Vector skin: document.addEventListener('DOMContentLoaded', function () { document.querySelectorAll('a').forEach(function (link) { if (link.hostname === location.hostname) { link.removeAttribute('target'); } }); }); new MutationObserver(function (mutations) { mutations.forEach(function (m) { m.addedNodes.forEach(function (node) { if (node.nodeType === 1 && node.tagName === 'A' && node...." |
No edit summary |
||
| Line 1: | Line 1: | ||
/* All JavaScript here will be loaded for users of the Vector skin */ | /* All JavaScript here will be loaded for users of the Vector skin */ | ||
function removeTargetAttrs(scope = document) { | |||
scope.querySelectorAll('a[target]').forEach(link => { | |||
if (link.hostname === location.hostname) { | if (link.hostname === location.hostname) { | ||
link.removeAttribute('target'); | link.removeAttribute('target'); | ||
} | } | ||
}); | }); | ||
} | |||
document.addEventListener('DOMContentLoaded', function () { | |||
removeTargetAttrs(); | |||
}); | }); | ||
new MutationObserver | new MutationObserver(mutations => { | ||
mutations.forEach | mutations.forEach(m => { | ||
m.addedNodes.forEach( | m.addedNodes.forEach(node => { | ||
if (node.nodeType === 1) { | if (node.nodeType === 1) { | ||
node. | if (node.tagName === 'A') { | ||
removeTargetAttrs(node.parentNode || node); | |||
} else { | |||
removeTargetAttrs(node); | |||
} | } | ||
} | } | ||
}); | }); | ||
}); | }); | ||
}).observe(document.body, { childList: true, subtree: true }); | }).observe(document.body, { childList: true, subtree: true }); | ||
Latest revision as of 08:00, 25 June 2025
/* All JavaScript here will be loaded for users of the Vector skin */
function removeTargetAttrs(scope = document) {
scope.querySelectorAll('a[target]').forEach(link => {
if (link.hostname === location.hostname) {
link.removeAttribute('target');
}
});
}
document.addEventListener('DOMContentLoaded', function () {
removeTargetAttrs();
});
new MutationObserver(mutations => {
mutations.forEach(m => {
m.addedNodes.forEach(node => {
if (node.nodeType === 1) {
if (node.tagName === 'A') {
removeTargetAttrs(node.parentNode || node);
} else {
removeTargetAttrs(node);
}
}
});
});
}).observe(document.body, { childList: true, subtree: true });