Jump to content

MediaWiki:Common.js: Difference between revisions

From The Final Nights
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


       // Add the desired dark theme class
       // --- Force Dark Mode ---
      classList.add( 'vector-theme-dark' );


       // Remove potentially conflicting classes added by the skin
       // Remove potentially conflicting light mode classes
       classList.remove( 'vector-feature-night-mode-disabled' );
       if (classList.contains('vector-theme-light')) {
       classList.remove( 'skin-theme-clientpref-day' );
          classList.remove('vector-theme-light');
      // Just in case, also remove the opposite preference class if present
          appliedTheme = true;
      classList.remove( 'skin-theme-clientpref-night' );
      }
      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.' );
      }


      console.log( 'Applied dark theme and removed conflicting classes via Common.js' );
   } );
   } );
} );
} );

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.' );
      }

  } );
} );