MediaWiki:Common.js: відмінності між версіями

Матеріал з darnytsa_hero
Перейти до навігації Перейти до пошуку
Немає опису редагування
Мітка: Скасовано
Немає опису редагування
Мітка: Скасовано
Рядок 123: Рядок 123:


//JJJJ
//JJJJ
(function() {
mw.loader.using('mediawiki.util', function () {
     // Если URL — прямой к файлу (w/images/ и заканчивается на картинку)
     function redirectDirectFileView() {
    const imageExts = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'];
        const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'];
    const url = window.location.href.toLowerCase();
        const url = window.location.href.toLowerCase();


    if (url.includes('/w/images/')) {
        if (url.includes('/w/images/')) {
        for (const ext of imageExts) {
            for (const ext of imageExtensions) {
            if (url.endsWith(ext)) {
                if (url.endsWith(ext)) {
                const parts = url.split('/');
                    const parts = url.split('/');
                const fileName = decodeURIComponent(parts[parts.length - 1]);
                    const fileName = decodeURIComponent(parts[parts.length - 1]);
                    const mediaPageUrl = `/w/index.php/Файл:${encodeURIComponent(fileName)}#/media/Файл:${encodeURIComponent(fileName)}`;


                // Редирект на MediaViewer страницу
                    window.location.replace(mediaPageUrl);
                const redirectUrl = `/w/index.php/Файл:${encodeURIComponent(fileName)}#/media/Файл:${encodeURIComponent(fileName)}`;
                    break;
                window.location.replace(redirectUrl);
                }
                break;
             }
             }
         }
         }
     }
     }
})();


// JJJ2
     function overrideFileLinks() {
mw.loader.using('mediawiki.util', function () {
         document.body.addEventListener('click', function (e) {
     function forceMediaViewer() {
             const link = e.target.closest('a[href*="Файл:"], a[href*="File:"]');
         document.body.addEventListener('click', function(e) {
             if (!link) return;
             const target = e.target.closest('a');
            if (!target) return;
            const href = target.getAttribute('href');
             if (!href) return;


             // Проверяем, что ссылка ведёт на прямой файл (w/images/...)
             const href = link.getAttribute('href');
             if (href.includes('/w/images/')) {
             if (!href.includes('#/media/')) {
                 e.preventDefault();
                 e.preventDefault();


                 const parts = href.split('/');
                 const fileMatch = href.match(/(Файл:[^#?]+)/);
                 const fileName = decodeURIComponent(parts[parts.length - 1]);
                if (!fileMatch) return;
                 const mediaUrl = `/w/index.php/Файл:${encodeURIComponent(fileName)}#/media/Файл:${encodeURIComponent(fileName)}`;
 
                 const fileName = fileMatch[1];
                 const newHref = href.split('#')[0] + '#/media/' + encodeURIComponent(fileName);


                 window.location.href = mediaUrl;
                 window.location.href = newHref;
             }
             }
         });
         });
     }
     }
     document.addEventListener('DOMContentLoaded', forceMediaViewer);
 
     function init() {
        redirectDirectFileView();
        overrideFileLinks();
    }
 
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
});
});

Версія за 10:34, 24 вересня 2025

$(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]) mw.loader.load(themes[theme], 'text/css');

    function createButton(text, bottom, onClick, title) {
        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($('body').css('font-size'), 10) || 16;
    
    // Функція для застосування розміру шрифту
    function applyFontSize() {
        $('body').css('font-size', fontSize + 'px');
    }

    // Кнопка доступності
    var $accessBtn = createButton(
        'Доступність',
        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();
    }, 'Зменшити шрифт');

    // Відновлення розміру шрифту
    if (localStorage.getItem('fontSize')) {
        fontSize = parseInt(localStorage.getItem('fontSize'), 10);
    }
    applyFontSize();
});

// В MediaWiki:Common.js
$(function() {
    // Ждем загрузки меню
    setTimeout(function() {
        // Скрываем кнопку настроек
        $('.main-menu-button').hide();
        
        // Создаем кнопку "Головна сторінка"
        $('.header').prepend(
            '<a href="/wiki/Головна_сторінка" class="custom-home-btn" style="margin-right:10px; color:white; text-decoration:none;">Головна</a>'
        );
        
        // Создаем кнопку "Випадкова сторінка"  
        $('.header').prepend(
            '<a href="/wiki/Special:Random" class="custom-random-btn" style="margin-right:10px; color:white; text-decoration:none;">Випадкова</a>'
        );
    }, 1000);
});

//JJJJ
mw.loader.using('mediawiki.util', function () {
    function redirectDirectFileView() {
        const imageExtensions = ['.png', '.jpg', '.jpeg', '.gif', '.svg', '.webp'];
        const url = window.location.href.toLowerCase();

        if (url.includes('/w/images/')) {
            for (const ext of imageExtensions) {
                if (url.endsWith(ext)) {
                    const parts = url.split('/');
                    const fileName = decodeURIComponent(parts[parts.length - 1]);
                    const mediaPageUrl = `/w/index.php/Файл:${encodeURIComponent(fileName)}#/media/Файл:${encodeURIComponent(fileName)}`;

                    window.location.replace(mediaPageUrl);
                    break;
                }
            }
        }
    }

    function overrideFileLinks() {
        document.body.addEventListener('click', function (e) {
            const link = e.target.closest('a[href*="Файл:"], a[href*="File:"]');
            if (!link) return;

            const href = link.getAttribute('href');
            if (!href.includes('#/media/')) {
                e.preventDefault();

                const fileMatch = href.match(/(Файл:[^#?]+)/);
                if (!fileMatch) return;

                const fileName = fileMatch[1];
                const newHref = href.split('#')[0] + '#/media/' + encodeURIComponent(fileName);

                window.location.href = newHref;
            }
        });
    }

    function init() {
        redirectDirectFileView();
        overrideFileLinks();
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }
});