|
|
| (2 intermediate revisions by the same user not shown) |
| 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. */ |
| 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() {
| |
| const stripRedInline = el => {
| |
| const s = el.getAttribute('style');
| |
| if (!s) return;
| |
| 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 => {
| |
| for (const m of muts) {
| |
| if (m.type === 'attributes' && m.attributeName === 'style') {
| |
| stripRedInline(m.target);
| |
| }
| |
| 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
| |
| document.querySelectorAll('*').forEach(stripRedInline);
| |
| })();
| |