MediaWiki:Common.js: Difference between revisions

From JP1 Remotes Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
document.querySelector('.mw-wiki-logo')?.removeAttribute('style');
mw.hook('wikipage.content').add(function($content) {
  $content.find('*').each(function(_, el) {
    const style = el.getAttribute('style');
    if (!style) return;
    if (/\b(red)\b/i.test(style) && (/\bborder\b|\boutline\b|\bbox-shadow\b/i.test(style))) {
      el.removeAttribute('style');
    }
  });
});
(function() {
(function() {
   const stripRedInline = el => {
   const target = document.querySelector('.mw-wiki-logo');
    const s = el.getAttribute('style');
  if (target) {
    if (!s) return;
     target.removeAttribute('style');
     if (/\b(red)\b/i.test(s) && (/\bborder\b|\boutline\b|\bbox-shadow\b/i.test(s))) {
   }
      el.removeAttribute('style');
    }
   };


   const obs = new MutationObserver(muts => {
   const observer = new MutationObserver(mutations => {
     for (const m of muts) {
     mutations.forEach(m => {
       if (m.type === 'attributes' && m.attributeName === 'style') {
       if (m.type === 'attributes' && m.attributeName === 'style') {
         stripRedInline(m.target);
         m.target.removeAttribute('style');
       }
       }
      m.addedNodes.forEach(node => {
     });
        if (node.nodeType === 1) {
          stripRedInline(node);
          node.querySelectorAll?.('*').forEach(stripRedInline);
        }
      });
     }
  });
 
  obs.observe(document.documentElement, {
    attributes: true,
    attributeFilter: ['style'],
    subtree: true,
    childList: true
   });
   });


   // Initial sweep
   if (target) {
  document.querySelectorAll('*').forEach(stripRedInline);
    observer.observe(target, { attributes: true });
  }
})();
})();

Revision as of 15:49, 18 November 2025

/* Any JavaScript here will be loaded for all users on every page load. */
(function() {
  const target = document.querySelector('.mw-wiki-logo');
  if (target) {
    target.removeAttribute('style');
  }

  const observer = new MutationObserver(mutations => {
    mutations.forEach(m => {
      if (m.type === 'attributes' && m.attributeName === 'style') {
        m.target.removeAttribute('style');
      }
    });
  });

  if (target) {
    observer.observe(target, { attributes: true });
  }
})();