Увага: Після публікування слід очистити кеш браузера, щоб побачити зміни.

  • Firefox / Safari: тримайте Shift, коли натискаєте Оновити, або натисніть Ctrl-F5 чи Ctrl-Shift-R (⌘-R на Apple Mac)
  • Google Chrome: натисніть Ctrl-Shift-R (⌘-Shift-R на Apple Mac)
  • Edge: тримайте Ctrl, коли натискаєте Оновити, або натисніть Ctrl-F5.
// =========================
// ОСНОВНИЙ КОД ДЛЯ ТЕМ, ДОСТУПНОСТІ ТА ЛУПИ
// =========================
$(function () {
    // Теми
    var themes = {
        light: '/w/index.php?title=MediaWiki:Light.css&action=raw&ctype=text/css',
        dark: '/w/index.php?title=MediaWiki:Dark.css&action=raw&ctype=text/css'
    };

    var theme = localStorage.getItem('selectedTheme');
    if (!theme) {
        theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    }
    
    // Завантажуємо тему
    if (themes[theme]) {
        // Видаляємо попередні теми, щоб уникнути конфліктів
        $('link[title="light"], link[title="dark"]').remove();
        mw.loader.load(themes[theme], 'text/css');
    }

    function createButton(text, bottom, onClick, title) {
        // Перевіряємо чи кнопка вже існує
        var existingBtn = $('button').filter(function() {
            return $(this).text() === text;
        });
        if (existingBtn.length > 0) return existingBtn;
        
        var $btn = $('<button>').text(text).attr('title', title).css({
            position: 'fixed',
            bottom: bottom + 'px',
            right: '10px',
            padding: '10px 16px',
            border: 'none',
            borderRadius: '25px',
            background: '#1a73e8',
            color: '#ffffff',
            fontWeight: 'bold',
            fontSize: '14px',
            cursor: 'pointer',
            zIndex: 9999,
            textAlign: 'center',
            boxShadow: '0 2px 6px rgba(0,0,0,0.3)',
            whiteSpace: 'nowrap'
        }).click(onClick);
        $('body').append($btn);
        return $btn;
    }

    // Кнопка Темна/Світла тема
    var $themeBtn = createButton(
        theme === 'dark' ? 'Світла тема ☀️' : 'Темна тема 🌙',
        10,
        function () {
            var newTheme = theme === 'dark' ? 'light' : 'dark';
            localStorage.setItem('selectedTheme', newTheme);
            location.reload();
        },
        'Змінити тему'
    );

    // Змінна для зберігання розміру шрифту
    var fontSize = parseInt(localStorage.getItem('fontSize')) || parseInt($('body').css('font-size')) || 16;
    
    // Функція для застосування розміру шрифту
    function applyFontSize() {
        $('body').css('font-size', fontSize + 'px');
        // Застосовуємо також до конкретних елементів
        $('.mw-body, .mw-body-content, p, li, span, a').css('font-size', fontSize + 'px');
    }

    // Кнопка доступності
    var $accessBtn = createButton(
        localStorage.getItem('accessibilityMode') === 'on' ? 'Доступність ON' : 'Доступність OFF',
        70,
        function () {
            if (!$('body').hasClass('accessibility-mode')) {
                $('body').addClass('accessibility-mode');
                localStorage.setItem('accessibilityMode', 'on');
                $accessBtn.css('background', '#ff6600');
                $accessBtn.text('Доступність ON');
            } else {
                $('body').removeClass('accessibility-mode');
                localStorage.setItem('accessibilityMode', 'off');
                $accessBtn.css('background', '#1a73e8');
                $accessBtn.text('Доступність OFF');
            }
        },
        'Увімкнути/вимкнути режим доступності'
    );

    // Відновлення стану доступності
    if (localStorage.getItem('accessibilityMode') === 'on') {
        $('body').addClass('accessibility-mode');
        $accessBtn.css('background', '#ff6600');
        $accessBtn.text('Доступність ON');
    }

    // Лупа
    createButton('🔍 +', 130, function () {
        fontSize += 2;
        if (fontSize > 30) fontSize = 30;
        localStorage.setItem('fontSize', fontSize);
        applyFontSize();
    }, 'Збільшити шрифт');

    createButton('🔍 -', 170, function () {
        fontSize -= 2;
        if (fontSize < 12) fontSize = 12;
        localStorage.setItem('fontSize', fontSize);
        applyFontSize();
    }, 'Зменшити шрифт');

    // Застосовуємо розмір шрифту
    applyFontSize();
});

// =========================
// КНОПКА ВИПАДКОВА СТОРІНКА (спрощена версія)
// =========================
function createRandomButton() {
    if (document.getElementById('float-random-btn') || !document.body.classList.contains('skin-minerva')) {
        return;
    }
    
    const btn = document.createElement('button');
    btn.id = 'float-random-btn';
    btn.innerHTML = '🎲 Випадкова';
    btn.title = 'Випадкова сторінка';
    btn.style.cssText = `
        position: fixed;
        bottom: 100px;
        right: 15px;
        z-index: 9998;
        background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%);
        color: white;
        border: none;
        padding: 12px 18px;
        border-radius: 25px;
        font-size: 16px;
        font-weight: bold;
        cursor: pointer;
        box-shadow: 0 4px 15px rgba(0,0,0,0.3);
        display: flex;
        align-items: center;
        gap: 8px;
        transition: all 0.3s ease;
    `;
    
    btn.addEventListener('click', function() {
        window.location.href = '/w/index.php/Спеціальна:Випадкова_сторінка';
    });
    
    btn.addEventListener('mouseenter', function() {
        this.style.transform = 'scale(1.05)';
        this.style.boxShadow = '0 6px 20px rgba(0,0,0,0.4)';
    });
    
    btn.addEventListener('mouseleave', function() {
        this.style.transform = 'scale(1)';
        this.style.boxShadow = '0 4px 15px rgba(0,0,0,0.3)';
    });
    
    document.body.appendChild(btn);
}

// =========================
// ПРИХОВАННЯ ЕЛЕМЕНТІВ У МОБІЛЬНІЙ ВЕРСІЇ
// =========================
function hideMobileElements() {
    if (!document.body.classList.contains('skin-minerva')) return;
    
    // Приховуємо елементи з текстом "Відмова"
    setTimeout(() => {
        const elements = document.querySelectorAll('*');
        elements.forEach(element => {
            if (element.textContent && element.textContent.includes('Відмова')) {
                element.style.display = 'none';
                const parentLi = element.closest('li');
                if (parentLi) parentLi.style.display = 'none';
            }
        });
        
        // Приховуємо за посиланням
        const links = document.querySelectorAll('a[href*="%D0%92%D1%96%D0%B4%D0%BC%D0%BE%D0%B2%D0%B0"]');
        links.forEach(link => {
            link.style.display = 'none';
            const parentLi = link.closest('li');
            if (parentLi) parentLi.style.display = 'none';
        });
    }, 1000);
}

// =========================
// OVERLAY ДЛЯ ЗОБРАЖЕНЬ (спрощена версія)
// =========================
function initImageOverlay() {
    // Простий оверлей для зображень
    document.addEventListener('click', function(e) {
        if (e.target.tagName === 'IMG' && e.target.width > 100) {
            e.preventDefault();
            
            const overlay = document.createElement('div');
            overlay.style.cssText = `
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: rgba(0,0,0,0.9);
                display: flex;
                justify-content: center;
                align-items: center;
                z-index: 10000;
                cursor: pointer;
            `;
            
            const img = document.createElement('img');
            img.src = e.target.src;
            img.style.cssText = `
                max-width: 90%;
                max-height: 90%;
                object-fit: contain;
            `;
            
            overlay.appendChild(img);
            document.body.appendChild(overlay);
            
            overlay.addEventListener('click', function() {
                document.body.removeChild(overlay);
            });
        }
    });
}

// =========================
// ЗАГАЛЬНИЙ ІНІЦІАЛІЗАТОР
// =========================
document.addEventListener('DOMContentLoaded', function() {
    // Ініціалізуємо оверлей
    initImageOverlay();
    
    // Для мобільної версії
    if (document.body.classList.contains('skin-minerva')) {
        // Приховуємо елементи
        hideMobileElements();
        
        // Створюємо кнопку випадкової сторінки
        createRandomButton();
        
        // Додаткова перевірка через 2 секунди
        setTimeout(() => {
            if (!document.getElementById('float-random-btn')) {
                createRandomButton();
            }
            hideMobileElements();
        }, 2000);
    }
});

// Додаткова перевірка при повному завантаженні
window.addEventListener('load', function() {
    if (document.body.classList.contains('skin-minerva')) {
        setTimeout(createRandomButton, 500);
    }
});

// Резервний виклик
setTimeout(function() {
    if (document.body.classList.contains('skin-minerva') && !document.getElementById('float-random-btn')) {
        createRandomButton();
    }
}, 3000);