Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Tag: Manual revert
 
(6 intermediate revisions by the same user not shown)
Line 9: Line 9:


$(function() {
$(function() {
     function switchTab(from) {
    // Handle redirects with tab switching
    var $redirect = $('span.mw-redirectedfrom a');
    if ($redirect.length) {
        waitAndSwitchTab($redirect.text().trim());
    }
 
    // Handle hash-based tab switching
    if (window.location.hash && window.location.hash.indexOf('tabber-tabpanel') !== -1) {
        waitAndSwitchTab(null, window.location.hash.substring(1));
    }
 
    // Intercept search result clicks
    document.addEventListener('click', function(e) {
        var link = e.target.closest('a');
        if (!link) return;
        if (!link.closest('.citizen-typeahead')) return;
 
        var redirectLabel = link.querySelector('.citizen-typeahead__labelItem[title*="redirect from"]');
        if (redirectLabel) {
            var match = redirectLabel.getAttribute('title').match(/redirect from (.+)\)/);
            if (match) {
                e.preventDefault();
                e.stopPropagation();
                window.location.href = '/' + encodeURIComponent(match[1]);
            }
        }
    }, true);
 
     function waitAndSwitchTab(from, panelId) {
         var observer = new MutationObserver(function(mutations, obs) {
         var observer = new MutationObserver(function(mutations, obs) {
             var panels = document.querySelectorAll('[role="tabpanel"]');
             var panels = document.querySelectorAll('[role="tabpanel"]');
             if (panels.length > 0) {
             if (panels.length > 0) {
                 panels.forEach(function(panel) {
                 if (panelId) {
                    if (panel.textContent.indexOf(from) !== -1) {
                    var tab = document.querySelector('[aria-controls="' + panelId + '"]');
                        var panelId = panel.getAttribute('id');
                    if (tab) tab.click();
                        var tab = document.querySelector('[aria-controls="' + panelId + '"]');
                } else if (from) {
                        if (tab) {
                    panels.forEach(function(panel) {
                            tab.click();
                        if (panel.textContent.indexOf(from) !== -1) {
                            var id = panel.getAttribute('id');
                            var tab = document.querySelector('[aria-controls="' + id + '"]');
                            if (tab) tab.click();
                         }
                         }
                     }
                     });
                 });
                 }
                 obs.disconnect();
                 obs.disconnect();
             }
             }
Line 27: Line 58:
         observer.observe(document.body, { childList: true, subtree: true });
         observer.observe(document.body, { childList: true, subtree: true });
     }
     }
});


    // Check for redirect notice
    var $redirect = $('span.mw-redirectedfrom a');
    if ($redirect.length) {
        switchTab($redirect.text().trim());
        return;
    }
    // Check URL for redirect parameter
    var redirectFrom = mw.util.getParamValue('redirect');
    if (redirectFrom === 'no') {
        return;
    }


    // Check if we came from a different title than the current page
$(function() {
     var fromTitle = mw.util.getParamValue('title');
     var siteName = ' - Stargaze Community Wiki';
     if (fromTitle && fromTitle !== mw.config.get('wgPageName')) {
     if (document.title.indexOf(siteName) === -1) {
         switchTab(fromTitle.replace(/_/g, ' '));
         document.title = document.title + siteName;
     }
     }
});
});

Latest revision as of 18:41, 13 April 2026

/* Any JavaScript here will be loaded for all users on every page load. */
$(function() {
    $('[accesskey="t"]').removeAttr('accesskey');
    $('[accesskey="n"]').removeAttr('accesskey');
    $('#pt-mytalk').remove();
    $('#ca-talk').remove();
    $('#ca-addsection').remove();
});

$(function() {
    // Handle redirects with tab switching
    var $redirect = $('span.mw-redirectedfrom a');
    if ($redirect.length) {
        waitAndSwitchTab($redirect.text().trim());
    }

    // Handle hash-based tab switching
    if (window.location.hash && window.location.hash.indexOf('tabber-tabpanel') !== -1) {
        waitAndSwitchTab(null, window.location.hash.substring(1));
    }

    // Intercept search result clicks
    document.addEventListener('click', function(e) {
        var link = e.target.closest('a');
        if (!link) return;
        if (!link.closest('.citizen-typeahead')) return;

        var redirectLabel = link.querySelector('.citizen-typeahead__labelItem[title*="redirect from"]');
        if (redirectLabel) {
            var match = redirectLabel.getAttribute('title').match(/redirect from (.+)\)/);
            if (match) {
                e.preventDefault();
                e.stopPropagation();
                window.location.href = '/' + encodeURIComponent(match[1]);
            }
        }
    }, true);

    function waitAndSwitchTab(from, panelId) {
        var observer = new MutationObserver(function(mutations, obs) {
            var panels = document.querySelectorAll('[role="tabpanel"]');
            if (panels.length > 0) {
                if (panelId) {
                    var tab = document.querySelector('[aria-controls="' + panelId + '"]');
                    if (tab) tab.click();
                } else if (from) {
                    panels.forEach(function(panel) {
                        if (panel.textContent.indexOf(from) !== -1) {
                            var id = panel.getAttribute('id');
                            var tab = document.querySelector('[aria-controls="' + id + '"]');
                            if (tab) tab.click();
                        }
                    });
                }
                obs.disconnect();
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    }
});


$(function() {
    var siteName = ' - Stargaze Community Wiki';
    if (document.title.indexOf(siteName) === -1) {
        document.title = document.title + siteName;
    }
});