MediaWiki:Common.js: различия между версиями

Материал из Лигапедия Reborn
Перейти к навигации Перейти к поиску
Строка 1: Строка 1:
(function () {
 
    var storageKey = 'ligapedia-dark-mode';
 
 
    if (localStorage.getItem(storageKey) === '1') {
 
        document.documentElement.classList.add('dark-mode');
 
 
        var style = document.createElement('style');
 
        style.textContent = `
 
            html.dark-mode,
 
            html.dark-mode body {
 
                background-color: #202231 !important;
 
            }
 
        `;
 
 
        if (document.head) {
 
            document.head.appendChild(style);
 
        } else {
 
            document.documentElement.appendChild(style);
 
        }
 
    }
 
})();
 
 
 
mw.loader.using(['mediawiki.util', 'mediawiki.storage']).done(function () {
 
mw.loader.using(['mediawiki.util', 'mediawiki.storage']).done(function () {
 +
var storageKey = 'ligapedia-dark-mode';
 +
var isDark = mw.storage.get(storageKey) === '1';
  
    var storageKey = 'ligapedia-dark-mode';
+
function setTheme(dark) {
    var isDark = mw.storage.get(storageKey) === '1';
+
if (dark) {
 
+
document.documentElement.classList.add('dark-mode');
    function setTheme(dark) {
+
mw.storage.set(storageKey, '1');
 
+
} else {
        if (dark) {
+
document.documentElement.classList.remove('dark-mode');
            document.documentElement.classList.add('dark-mode');
+
mw.storage.set(storageKey, '0');
            mw.storage.set(storageKey, '1');
+
}
        } else {
+
isDark = dark;
            document.documentElement.classList.remove('dark-mode');
+
}
            mw.storage.set(storageKey, '0');
 
        }
 
 
 
        isDark = dark;
 
    }
 
 
 
    if (isDark) {
 
        document.documentElement.classList.add('dark-mode');
 
    }
 
 
 
    var link = mw.util.addPortletLink(
 
        'p-personal',
 
        '#',
 
        'Тёмная тема',
 
        'pt-dark-mode-toggle',
 
        'Переключить тему'
 
    );
 
 
 
    if (link) {
 
 
 
        $(link).on('click', function (e) {
 
 
 
            e.preventDefault();
 
 
 
            setTheme(!isDark);
 
 
 
            $(this).text(
 
                isDark ? 'Светлая тема' : 'Тёмная тема'
 
            );
 
  
        });
+
if (isDark) {
 +
document.documentElement.classList.add('dark-mode');
 +
}
  
        $(link).text(
+
var link = mw.util.addPortletLink(
            isDark ? 'Светлая тема' : 'Тёмная тема'
+
'p-personal',
        );
+
'#',
    }
+
'Тёмная тема',
 +
'pt-dark-mode-toggle',
 +
'Переключить тему'
 +
);
  
 +
if (link) {
 +
$(link).on('click', function (e) {
 +
e.preventDefault();
 +
setTheme(!isDark);
 +
$(this).text(isDark ? 'Светлая тема' : 'Тёмная тема');
 +
});
 +
$(link).text(isDark ? 'Светлая тема' : 'Тёмная тема');
 +
}
 
});
 
});

Версия 17:25, 12 августа 2026

mw.loader.using(['mediawiki.util', 'mediawiki.storage']).done(function () {
	var storageKey = 'ligapedia-dark-mode';
	var isDark = mw.storage.get(storageKey) === '1';

	function setTheme(dark) {
		if (dark) {
			document.documentElement.classList.add('dark-mode');
			mw.storage.set(storageKey, '1');
		} else {
			document.documentElement.classList.remove('dark-mode');
			mw.storage.set(storageKey, '0');
		}
		isDark = dark;
	}

	if (isDark) {
		document.documentElement.classList.add('dark-mode');
	}

	var link = mw.util.addPortletLink(
		'p-personal',
		'#',
		'Тёмная тема',
		'pt-dark-mode-toggle',
		'Переключить тему'
	);

	if (link) {
		$(link).on('click', function (e) {
			e.preventDefault();
			setTheme(!isDark);
			$(this).text(isDark ? 'Светлая тема' : 'Тёмная тема');
		});
		$(link).text(isDark ? 'Светлая тема' : 'Тёмная тема');
	}
});