Zum Inhalt springen

MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Korstipedia
Keine Bearbeitungszusammenfassung
use better dark mode check
Zeile 2: Zeile 2:
function handleDarkMode(enable) {
function handleDarkMode(enable) {
     var $darkModeLink = $( '.ext-darkmode-link' );
     var $darkModeLink = $( '.ext-darkmode-link' );
     var isDarkMode = $darkModeLink.find( '.mw-ui-icon-moon' )[0] === undefined;
     const isDarkMode= document.documentElement.classList.contains( 'client-darkmode' );
   
   
console.log("Dark mode is" + isDarkMode);
console.log("Dark mode is" + isDarkMode);

Version vom 18. Januar 2024, 01:51 Uhr

var darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
function handleDarkMode(enable) {
    var $darkModeLink = $( '.ext-darkmode-link' );
    const isDarkMode= document.documentElement.classList.contains( 'client-darkmode' );
 
console.log("Dark mode is" + isDarkMode);
    if (isDarkMode !== enable) {
        document.getElementsByClassName("ext-darkmode-link")[0].click();
    }
}
$( document ).ready(function() {
  handleDarkMode(darkModeMediaQuery.matches);
});
darkModeMediaQuery.onchange = function (event) {
  handleDarkMode(event.matches);
};