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

Страница интерфейса MediaWiki
мНет описания правки
Метка: отменено
мНет описания правки
Метка: отменено
Строка 1: Строка 1:
// Объявляем функцию глобально
window.toggleTheme = function() {
window.toggleTheme = function() {
     document.body.classList.toggle('dark-theme');
     document.body.classList.toggle('dark-theme');
Строка 5: Строка 4:
};
};


// Загружаем сохраненную тему
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener('DOMContentLoaded', function() {
     var savedTheme = localStorage.getItem('theme');
     var savedTheme = localStorage.getItem('theme');
     if (savedTheme === 'dark') {
     if (savedTheme === 'dark') document.body.classList.add('dark-theme');
        document.body.classList.add('dark-theme');
    }
});
});


// Добавляем кнопку для Citizen
mw.hook('citizen.load').add(function() {
mw.hook('citizen.load').add(function() {
    // Создаем кнопку
     var button = document.createElement('button');
     var button = document.createElement('button');
     button.innerHTML = '🌓 Тема';
     button.textContent = '🌓 Тема';
     button.style.margin = '0 10px';
     button.style.cssText = 'margin: 0 10px; padding: 8px 12px; cursor: pointer;';
    button.style.padding = '8px 12px';
    button.style.cursor = 'pointer';
    button.style.background = 'var(--background-color)';
    button.style.color = 'var(--color-base)';
    button.style.border = '1px solid var(--border-color-base)';
    button.style.borderRadius = '4px';
     button.onclick = toggleTheme;
     button.onclick = toggleTheme;


    // Вставляем кнопку в верхнюю панель Citizen
     var headerTools = document.querySelector('.citizen-header__tools');
     var headerTools = document.querySelector('.citizen-header__tools');
     if (headerTools) {
     if (headerTools) {
         headerTools.insertBefore(button, headerTools.firstChild);
         headerTools.insertBefore(button, headerTools.firstChild);
    } else {
        var citizenHeader = document.querySelector('.citizen-header');
        if (citizenHeader) {
            citizenHeader.appendChild(button);
        }
     }
     }
});
     try {
     try {
     // Весь ваш код
     // Весь ваш код

Версия от 14:29, 1 апреля 2025

window.toggleTheme = function() {
    document.body.classList.toggle('dark-theme');
    localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light');
};

document.addEventListener('DOMContentLoaded', function() {
    var savedTheme = localStorage.getItem('theme');
    if (savedTheme === 'dark') document.body.classList.add('dark-theme');
});

mw.hook('citizen.load').add(function() {
    var button = document.createElement('button');
    button.textContent = '🌓 Тема';
    button.style.cssText = 'margin: 0 10px; padding: 8px 12px; cursor: pointer;';
    button.onclick = toggleTheme;

    var headerTools = document.querySelector('.citizen-header__tools');
    if (headerTools) {
        headerTools.insertBefore(button, headerTools.firstChild);
    }
});
    try {
    // Весь ваш код
} catch (error) {
    console.error('Ошибка в скрипте темы:', error);
}
});