Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

MediaWiki:Common.js

From Leeroopedia
Revision as of 14:02, 18 February 2026 by Admin (talk | contribs) (Fix: poll for vis.js before applying namespace colors)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Network Extension Enhancements - Filter external links, color by namespace.
 * vis.js is loaded asynchronously by the Network extension, so we poll
 * until window.vis.DataSet is available before monkey-patching.
 */
(function() {
    'use strict';
    var nsColors = {
        'Workflow':       {bg: '#4CAF50', border: '#2E7D32', font: '#1B5E20'},
        'Principle':      {bg: '#2196F3', border: '#1565C0', font: '#0D47A1'},
        'Implementation': {bg: '#FF9800', border: '#EF6C00', font: '#E65100'},
        'Artifact':       {bg: '#9C27B0', border: '#7B1FA2', font: '#4A148C'},
        'Heuristic':      {bg: '#F44336', border: '#C62828', font: '#B71C1C'},
        'Environment':    {bg: '#00BCD4', border: '#0097A7', font: '#006064'},
        'Resource':       {bg: '#795548', border: '#5D4037', font: '#3E2723'}
    };
    var excludedPrefixes = ['Template:', 'Category:', 'MediaWiki:', 'Special:', 'File:'];

    function applyPatch() {
        var originalUpdate = window.vis.DataSet.prototype.update;
        window.vis.DataSet.prototype.update = function(data, senderId) {
            if (!Array.isArray(data)) data = [data];
            data = data.filter(function(item) {
                var id = item.id || '', to = item.to || '', from = item.from || '';
                if (id.indexOf('http://') === 0 || id.indexOf('https://') === 0) return false;
                if (to.indexOf('http://') === 0 || to.indexOf('https://') === 0) return false;
                if (from.indexOf('http://') === 0 || from.indexOf('https://') === 0) return false;
                for (var i = 0; i < excludedPrefixes.length; i++) {
                    if (id.indexOf(excludedPrefixes[i]) === 0) return false;
                    if (to.indexOf(excludedPrefixes[i]) === 0) return false;
                    if (from.indexOf(excludedPrefixes[i]) === 0) return false;
                }
                return true;
            }).map(function(item) {
                if (item.id && !item.from && !item.to) {
                    for (var ns in nsColors) {
                        if (item.id.indexOf(ns + ':') === 0) {
                            item.color = {background: nsColors[ns].bg, border: nsColors[ns].border,
                                highlight: {background: nsColors[ns].bg, border: nsColors[ns].border}};
                            item.font = item.font || {};
                            item.font.color = nsColors[ns].font;
                            break;
                        }
                    }
                }
                return item;
            });
            return originalUpdate.call(this, data, senderId);
        };
    }

    /* Poll for vis.js readiness - it loads async via ResourceLoader */
    var attempts = 0;
    var maxAttempts = 100;
    var timer = setInterval(function() {
        attempts++;
        if (window.vis && window.vis.DataSet) {
            clearInterval(timer);
            applyPatch();
        } else if (attempts >= maxAttempts) {
            clearInterval(timer);
        }
    }, 100);
})();