Немає опису редагування
Немає опису редагування
Рядок 121: Рядок 121:
});
});


// Автоматическое исправление всех ссылок на изображения
$(document).ready(function() {
    // Исправляем все ссылки на файлы
    $('a[href*="/images/"]').each(function() {
        var href = $(this).attr('href');
        if (href && href.match(/\.(png|jpg|jpeg|gif)$/i)) {
            // Заменяем на ссылку на страницу файла вместо прямого открытия
            var newHref = href.replace(/\/images\//, '/wiki/File:');
            $(this).attr('href', newHref);
        }
    });
   
    // Для страниц с изображениями добавляем кнопку закрытия
    if (window.location.pathname.indexOf('/images/') !== -1) {
        addCloseButton();
    }
});


// Перенаправление с прямых ссылок на изображения обратно на страницу
function addCloseButton() {
if (window.location.pathname.match(/\/w\/images\//)) {
     var closeBtn = document.createElement('button');
    // Находим страницу, откуда пришли
     closeBtn.innerHTML = 'ЗАКРЫТЬ';
     var referrer = document.referrer;
    closeBtn.style.cssText = 'position:fixed; top:10px; right:10px; z-index:9999; background:red; color:white; padding:15px; font-size:20px; border:none; border-radius:5px; cursor:pointer;';
     if (referrer && referrer.match(/wiki\//)) {
    closeBtn.onclick = function() {
        // Показываем кнопку назад
        window.history.back();
        document.body.innerHTML = '<div style="position:fixed; top:20px; left:20px; z-index:10000; background:red; color:white; padding:15px; border-radius:5px;" onclick="window.history.back()">← НАЗАД</div>' + document.body.innerHTML;
    };
    }
    document.body.appendChild(closeBtn);
}
}