Jump to content

User:Rusalkii/hideRelisted.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>
// This should be incorporated in XFDC
(function() {
    let hidden = true; // Default to hidden
    var debug = true;
    
    function log(text) {
        if (debug) {
            console.log(text);
        }
    }
    
    // Check if on XfD page
    var venueHeadingLevel;
    if (mw.config.get('wgPageName').match(/Wikipedia:Redirects_for_discussion/) ||
        mw.config.get('wgPageName').match(/Wikipedia:Files_for_discussion/) ||
        mw.config.get('wgPageName').match(/Wikipedia:Miscellany_for_deletion/) ||
        mw.config.get('wgPageName').match(/Wikipedia:Templates_for_discussion/)) {
        venueHeadingLevel = '.mw-heading.mw-heading4'; 
    } else if (mw.config.get('wgPageName').match(/Wikipedia:Articles_for_deletion/) ||
               mw.config.get('wgPageName').match(/Wikipedia:Categories_for_discussion/) ||
               mw.config.get('wgPageName').match(/Commons:Deletion_requests/)) {
        venueHeadingLevel = '.mw-heading.mw-heading3';
    } else { 
        log('Not a deletion venue');
        return; // Exit if not on XfD page
    }
    
    const button = document.createElement('button');
    button.textContent = 'Show Relisted';
    button.style.cssText = 'position:fixed;bottom:40px;left:10px;z-index:100;padding:5px 10px;background:rgba(248, 249, 250, 0.8);border: 1px solid #ccc;border-radius:4px;cursor:pointer;'

    function addStyles() {
        const css = `
            .rfd-relisted {
            }
            .rfd-relisted.rfd-hidden {
                display: none;
            }
        `;
        
        $('<style>').text(css).appendTo('head');
    }
    
    function hideRelists() {
        const $ = jQuery;
        
        let relistedCount = 0;
        const headers = $(venueHeadingLevel);
        log(`Found ${headers.length} headers`);
        
        headers.each(function(index) {
            const header = $(this);
            const content = header.nextUntil(venueHeadingLevel);
            
            // Check if the relist symbol and text
            const contentClone = content.clone();
            const moveSymbol = contentClone.find('img[src*="Symbol_move_vote.svg"]');
            
            if (moveSymbol.length !== 0) {
                log(`Found relist at ${index} (header: ${header.text().substring(0, 30)}...)`);
                
	            // Add classes directly instead of wrapping
	            header.addClass('rfd-relisted');
	            content.addClass('rfd-relisted');
	            
	            // Toggle visibility
	            if (hidden) {
	                header.addClass('rfd-hidden');
	                content.addClass('rfd-hidden');
	            } else {
	                header.removeClass('rfd-hidden');
	                content.removeClass('rfd-hidden');
	            }                
                relistedCount++;
            }
        });
        
        log(`Processed ${relistedCount} relists`);
    }
    
    $(document).ready(function() {
        addStyles();
        hideRelists();
        document.querySelector('#mw-content-text').prepend(button);
    });
    
    button.onclick = () => {
        hidden = !hidden;
        hideRelists();
        button.textContent = hidden ? 'Show Relisted' : 'Hide Relisted';
    };
    
})();
//</nowiki>