Jump to content

MediaWiki:Common.js: Difference between revisions

From The Shivo Library
No edit summary
No edit summary
Line 2: Line 2:


/**
/**
  * Enforce Dark Mode for All Users and Remove Appearance Menu
  * Enforce Dark Mode, Remove Appearance Menu, and Enable Hamburger Menu for All Users
  */
  */
(function() {
(function() {
     // Function to enforce dark mode by adding necessary classes
     /**
    * Function to enforce dark mode by adding necessary classes
    */
     function enforceDarkMode() {
     function enforceDarkMode() {
        console.log('Enforcing dark mode for all users.');
         // Add classes to enforce dark mode
         // Add classes to enforce dark mode
         document.documentElement.classList.add('vector-feature-night-mode-enabled', 'skin-theme-clientpref-night');
         document.documentElement.classList.add('vector-feature-night-mode-enabled', 'skin-theme-clientpref-night');
Line 14: Line 14:
         // Remove any existing light mode classes if present
         // Remove any existing light mode classes if present
         document.documentElement.classList.remove('skin-theme-clientpref-day');
         document.documentElement.classList.remove('skin-theme-clientpref-day');
        console.log('Dark mode classes added:', document.documentElement.classList);
     }
     }


     // Function to remove the Appearance menu section
     /**
    * Function to remove the Appearance menu section
    */
     function removeAppearanceMenu() {
     function removeAppearanceMenu() {
         var appearanceSection = document.querySelector('#p-appearance');
         var appearanceSection = document.querySelector('#p-appearance');
         if (appearanceSection) {
         if (appearanceSection) {
             appearanceSection.style.display = 'none';
             appearanceSection.style.display = 'none';
            console.log('Appearance menu section removed.');
        } else {
            console.log('Appearance menu section not found.');
         }
         }
     }
     }


     // Execute functions after DOM is fully loaded
     /**
     if (document.readyState === 'complete' || document.readyState === 'interactive') {
    * Function to ensure the hamburger menu toggle is functional
    */
     function enableHamburgerMenu() {
        // Select the hamburger toggle button
        var hamburgerToggle = document.querySelector('#mw-navigation-toggle, #p-navigation-toggle, .hamburger-toggle');
 
        if (hamburgerToggle) {
            // Add a click event listener to toggle the navigation
            hamburgerToggle.addEventListener('click', function() {
                // Toggle a class on the body to show/hide the navigation
                document.body.classList.toggle('mw-navigation-open');
            });
        }
    }
 
    /**
    * Initialize all functions after DOM is ready
    */
    function initialize() {
         enforceDarkMode();
         enforceDarkMode();
         removeAppearanceMenu();
         removeAppearanceMenu();
        enableHamburgerMenu();
    }
    // Check if the DOM is already loaded
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        initialize();
     } else {
     } else {
         document.addEventListener('DOMContentLoaded', function() {
         document.addEventListener('DOMContentLoaded', initialize);
            enforceDarkMode();
            removeAppearanceMenu();
        });
     }
     }
})();
})();

Revision as of 08:25, 28 January 2025

/* Any JavaScript here will be loaded for all users on every page load. */

/**
 * Enforce Dark Mode, Remove Appearance Menu, and Enable Hamburger Menu for All Users
 */
(function() {
    /**
     * Function to enforce dark mode by adding necessary classes
     */
    function enforceDarkMode() {
        // Add classes to enforce dark mode
        document.documentElement.classList.add('vector-feature-night-mode-enabled', 'skin-theme-clientpref-night');

        // Remove any existing light mode classes if present
        document.documentElement.classList.remove('skin-theme-clientpref-day');
    }

    /**
     * Function to remove the Appearance menu section
     */
    function removeAppearanceMenu() {
        var appearanceSection = document.querySelector('#p-appearance');
        if (appearanceSection) {
            appearanceSection.style.display = 'none';
        }
    }

    /**
     * Function to ensure the hamburger menu toggle is functional
     */
    function enableHamburgerMenu() {
        // Select the hamburger toggle button
        var hamburgerToggle = document.querySelector('#mw-navigation-toggle, #p-navigation-toggle, .hamburger-toggle');

        if (hamburgerToggle) {
            // Add a click event listener to toggle the navigation
            hamburgerToggle.addEventListener('click', function() {
                // Toggle a class on the body to show/hide the navigation
                document.body.classList.toggle('mw-navigation-open');
            });
        }
    }

    /**
     * Initialize all functions after DOM is ready
     */
    function initialize() {
        enforceDarkMode();
        removeAppearanceMenu();
        enableHamburgerMenu();
    }

    // Check if the DOM is already loaded
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
        initialize();
    } else {
        document.addEventListener('DOMContentLoaded', initialize);
    }
})();