MediaWiki:Vector.js: Difference between revisions

From AviationSafetyX Wiki
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 */
document.addEventListener('DOMContentLoaded', function () {
 
   document.querySelectorAll('a').forEach(function (link) {
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(function (mutations) {
new MutationObserver(mutations => {
   mutations.forEach(function (m) {
   mutations.forEach(m => {
     m.addedNodes.forEach(function (node) {
     m.addedNodes.forEach(node => {
      if (node.nodeType === 1 && node.tagName === 'A' && node.hostname === location.hostname) {
        node.removeAttribute('target');
      }
       if (node.nodeType === 1) {
       if (node.nodeType === 1) {
         node.querySelectorAll?.('a').forEach(function (link) {
         if (node.tagName === 'A') {
           if (link.hostname === location.hostname) {
           removeTargetAttrs(node.parentNode || node);
            link.removeAttribute('target');
        } 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 });