Jump to content

This site is currently in alpha, so you will run into rough edges.

Please send feedback or ideas to connect@deeptech.wiki

MediaWiki:Gadget-WantedPagesMainspace.js: Difference between revisions

From The Deep Tech Wiki
No edit summary
Tag: Reverted
Undo revision 8139 by C (talk)
Tag: Undo
 
Line 9: Line 9:
         return;
         return;
     }
     }
    // Ensure container can host an overlay
    if (!container.style.position) {
        container.style.position = 'relative';
    }
    // Create loading overlay
    var overlay = document.createElement('div');
    overlay.className = 'wantedpages-loading-overlay';
    overlay.style.position = 'absolute';
    overlay.style.top = '0';
    overlay.style.left = '0';
    overlay.style.right = '0';
    overlay.style.bottom = '0';
    overlay.style.display = 'flex';
    overlay.style.alignItems = 'center';
    overlay.style.justifyContent = 'center';
    overlay.style.backgroundColor = 'white';
    overlay.style.zIndex = '9999';
    // Create loading circle
    var spinner = document.createElement('div');
    spinner.className = 'wantedpages-loading-spinner';
    spinner.style.width = '40px';
    spinner.style.height = '40px';
    spinner.style.borderRadius = '50%';
    spinner.style.border = '4px solid #ccc';
    spinner.style.borderTop = '4px solid #555';
    // Optional simple animation (no @keyframes needed if you want it static)
    // If you want it spinning, you'd add a <style> with keyframes instead.
    overlay.appendChild(spinner);
    container.appendChild(overlay);


     var bannedPrefixes = [
     var bannedPrefixes = [
Line 110: Line 76:
     });
     });


     // Replace old messy HTML and remove overlay
     // Replace old messy HTML
     container.innerHTML = '';
     container.innerHTML = '';
     container.appendChild(ul);
     container.appendChild(ul);
    // Overlay is gone once innerHTML is replaced; no need to explicitly remove it
});
});

Latest revision as of 09:50, 16 November 2025

// Gadget: WantedPagesMainspace
mw.loader.using(['mediawiki.Title', 'mediawiki.util'], function () {
    if (mw.config.get('wgPageName') !== 'Portal:WantedPages') {
        return;
    }

    var container = document.getElementById('wantedpages-mainonly');
    if (!container) {
        return;
    }

    var bannedPrefixes = [
        'Help:',
        'Template:',
        'The Deep Tech Wiki:',
        'Wikipedia:',
        'Wikipedia talk:',
        'WP:',
        'Wp:',
        'Project:',
        'Category:',
        'File:',
        'Module:',
        'MediaWiki:',
        'User:',
        'User talk:',
        'Talk:'
    ];

    function isBannedPrefix(text) {
        return bannedPrefixes.some(function (p) {
            return text.startsWith(p);
        });
    }

    var bannedExactTitles = [];

    function isBannedExact(text) {
        return bannedExactTitles.indexOf(text) !== -1;
    }

    var links = container.querySelectorAll('a');
    var seen = Object.create(null);
    var cleanedItems = [];

    links.forEach(function (link) {
        var href = link.getAttribute('href') || '';
        var text = (link.textContent || '').trim();
        if (!text) return;

        // Skip "### links" (they always point to Special:WhatLinksHere)
        if (href.includes('Special:WhatLinksHere')) return;

        if (isBannedPrefix(text) || isBannedExact(text)) return;

        var titleText = link.getAttribute('title') || text;
        var titleObj = mw.Title.newFromText(titleText);
        if (!titleObj) return;

        if (titleObj.getNamespaceId() !== 0) return;

        var key = titleObj.getPrefixedDb();
        if (seen[key]) return;
        seen[key] = true;

        cleanedItems.push(link.cloneNode(true));
    });

    // Build a new <ul> only with real content
    var ul = document.createElement('ul');

    cleanedItems.forEach(function (l) {
        var li = document.createElement('li');
        li.appendChild(l);
        ul.appendChild(li);
    });

    // Replace old messy HTML
    container.innerHTML = '';
    container.appendChild(ul);
});