Немає опису редагування
Мітка: Скасовано
Немає опису редагування
Мітка: Скасовано
Рядок 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();
    }
});
});