MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
$( function() { // Document ready shorthand | $( function() { // Document ready shorthand | ||
var classList = document.documentElement.classList; | var classList = document.documentElement.classList; | ||
var appliedTheme = false; // Flag to track if we made changes | |||
// | // --- Force Dark Mode --- | ||
// Remove potentially conflicting classes | // Remove potentially conflicting light mode classes | ||
classList.remove( 'vector-feature-night-mode-disabled' ); | if (classList.contains('vector-theme-light')) { | ||
classList. | classList.remove('vector-theme-light'); | ||
appliedTheme = true; | |||
} | |||
if (classList.contains('vector-feature-night-mode-disabled')) { | |||
classList.remove('vector-feature-night-mode-disabled'); | |||
appliedTheme = true; | |||
} | |||
if (classList.contains('skin-theme-clientpref-day')) { | |||
classList.remove('skin-theme-clientpref-day'); | |||
appliedTheme = true; | |||
} | |||
// Add required dark mode classes if not already present | |||
if (!classList.contains('vector-theme-dark')) { | |||
classList.add('vector-theme-dark'); | |||
appliedTheme = true; | |||
} | |||
// Hypothesis: Need to add the 'enabled' and 'night' counterparts | |||
if (!classList.contains('vector-feature-night-mode-enabled')) { | |||
classList.add('vector-feature-night-mode-enabled'); | |||
appliedTheme = true; | |||
} | |||
if (!classList.contains('skin-theme-clientpref-night')) { | |||
classList.add('skin-theme-clientpref-night'); | |||
appliedTheme = true; | |||
} | |||
// --- End Force Dark Mode --- | |||
if (appliedTheme) { | |||
console.log( 'Attempted to force dark theme classes via Common.js' ); | |||
} else { | |||
console.log( 'Dark theme classes may have already been present; no changes made by Common.js script.' ); | |||
} | |||
} ); | } ); | ||
} ); | } ); |
Revision as of 00:11, 16 April 2025
mw.loader.using( 'jquery' ).then( function () { $( function() { // Document ready shorthand var classList = document.documentElement.classList; var appliedTheme = false; // Flag to track if we made changes // --- Force Dark Mode --- // Remove potentially conflicting light mode classes if (classList.contains('vector-theme-light')) { classList.remove('vector-theme-light'); appliedTheme = true; } if (classList.contains('vector-feature-night-mode-disabled')) { classList.remove('vector-feature-night-mode-disabled'); appliedTheme = true; } if (classList.contains('skin-theme-clientpref-day')) { classList.remove('skin-theme-clientpref-day'); appliedTheme = true; } // Add required dark mode classes if not already present if (!classList.contains('vector-theme-dark')) { classList.add('vector-theme-dark'); appliedTheme = true; } // Hypothesis: Need to add the 'enabled' and 'night' counterparts if (!classList.contains('vector-feature-night-mode-enabled')) { classList.add('vector-feature-night-mode-enabled'); appliedTheme = true; } if (!classList.contains('skin-theme-clientpref-night')) { classList.add('skin-theme-clientpref-night'); appliedTheme = true; } // --- End Force Dark Mode --- if (appliedTheme) { console.log( 'Attempted to force dark theme classes via Common.js' ); } else { console.log( 'Dark theme classes may have already been present; no changes made by Common.js script.' ); } } ); } );