Jump to content

MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
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. */
$(document).ready(function() {
// Wait for the document to be fully loaded
    // Wait for the page to load
mw.hook('wikipage.content').add(function() {
    $(window).on('load', function() {
    // Check if we're on a search results page
        // Check if we're on the search page
    if (mw.config.get('wgCanonicalSpecialPageName') === 'Search') {
        if ($('.search-types').length) {
        // Small delay to ensure all search elements are loaded
            // Select the tab you want as default
        setTimeout(function() {
             // Options: 'Content pages', 'Multimedia', 'Everything'
             // Target the Content pages tab specifically
             var defaultTab = 'Content pages';
             var contentPagesTab = document.querySelector('.search-types a[data-target="mw-search-content"]') ||
                                document.querySelector('.search-types a:nth-child(1)');
              
              
             // Find and click the tab
             // Click the tab if found
             $('.search-types').find('a:contains("' + defaultTab + '")').click();
             if (contentPagesTab) {
         }
                contentPagesTab.click();
     });
                console.log('Search tab switched to Content pages');
            } else {
                console.log('Content pages tab not found');
            }
         }, 100);
     }
});
});