MediaWiki:Common.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* 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);
}
})();