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

Материал из Ascaron Online
Перейти к навигации Перейти к поиску
Нет описания правки
Метка: отменено
Нет описания правки
Метка: отменено
Строка 10: Строка 10:
loadingDiv.style.color = 'white';
loadingDiv.style.color = 'white';
loadingDiv.style.display = 'flex';
loadingDiv.style.display = 'flex';
loadingDiv.style.flexDirection = 'column';
loadingDiv.style.justifyContent = 'center';
loadingDiv.style.justifyContent = 'center';
loadingDiv.style.alignItems = 'center';
loadingDiv.style.alignItems = 'center';
loadingDiv.style.fontSize = '24px';
loadingDiv.style.fontSize = '24px';
loadingDiv.style.zIndex = '9999';
loadingDiv.style.zIndex = '9999';
loadingDiv.innerText = 'Загрузка...';


// Добавляем элемент на страницу
// Добавляем текст "Загрузка..."
var loadingText = document.createElement('div');
loadingText.innerText = 'Загрузка...';
loadingDiv.appendChild(loadingText);
 
// Создаем шкалу прогресса
var progressBarContainer = document.createElement('div');
progressBarContainer.style.width = '80%';
progressBarContainer.style.height = '20px';
progressBarContainer.style.background = 'rgba(255, 255, 255, 0.2)';
progressBarContainer.style.borderRadius = '10px';
progressBarContainer.style.marginTop = '20px';
 
var progressBar = document.createElement('div');
progressBar.style.height = '100%';
progressBar.style.width = '0';
progressBar.style.background = 'limegreen';
progressBar.style.borderRadius = '10px';
 
progressBarContainer.appendChild(progressBar);
loadingDiv.appendChild(progressBarContainer);
 
// Добавляем элемент загрузки на страницу
document.body.appendChild(loadingDiv);
document.body.appendChild(loadingDiv);


// Убираем эффект через 3 секунды
// Скрываем основной контент страницы
document.body.style.visibility = 'hidden';
 
// Функция для имитации прогресса загрузки
var progress = 0;
var interval = setInterval(function() {
    progress += 5;
    progressBar.style.width = progress + '%';
 
    // Когда прогресс достигает 100%, останавливаем интервал
    if (progress >= 100) {
        clearInterval(interval);
    }
}, 150); // Прогресс обновляется каждые 150 миллисекунд
 
// Убираем эффект загрузки через 3 секунды
window.onload = function() {
window.onload = function() {
     setTimeout(function() {
     setTimeout(function() {
        // Прячем элемент загрузки
         var loadingElement = document.getElementById('loading');
         var loadingElement = document.getElementById('loading');
         if (loadingElement) {
         if (loadingElement) {
             loadingElement.style.display = 'none';
             loadingElement.style.display = 'none';
         }
         }
        // Показываем основной контент страницы
        document.body.style.visibility = 'visible';
     }, 3000); // Задержка 3 секунды
     }, 3000); // Задержка 3 секунды
};
};





Версия от 07:28, 5 апреля 2025

// Создаем элемент загрузки
var loadingDiv = document.createElement('div');
loadingDiv.id = 'loading';
loadingDiv.style.position = 'fixed';
loadingDiv.style.top = '0';
loadingDiv.style.left = '0';
loadingDiv.style.width = '100%';
loadingDiv.style.height = '100%';
loadingDiv.style.background = 'rgba(0, 0, 0, 0.5)';
loadingDiv.style.color = 'white';
loadingDiv.style.display = 'flex';
loadingDiv.style.flexDirection = 'column';
loadingDiv.style.justifyContent = 'center';
loadingDiv.style.alignItems = 'center';
loadingDiv.style.fontSize = '24px';
loadingDiv.style.zIndex = '9999';

// Добавляем текст "Загрузка..."
var loadingText = document.createElement('div');
loadingText.innerText = 'Загрузка...';
loadingDiv.appendChild(loadingText);

// Создаем шкалу прогресса
var progressBarContainer = document.createElement('div');
progressBarContainer.style.width = '80%';
progressBarContainer.style.height = '20px';
progressBarContainer.style.background = 'rgba(255, 255, 255, 0.2)';
progressBarContainer.style.borderRadius = '10px';
progressBarContainer.style.marginTop = '20px';

var progressBar = document.createElement('div');
progressBar.style.height = '100%';
progressBar.style.width = '0';
progressBar.style.background = 'limegreen';
progressBar.style.borderRadius = '10px';

progressBarContainer.appendChild(progressBar);
loadingDiv.appendChild(progressBarContainer);

// Добавляем элемент загрузки на страницу
document.body.appendChild(loadingDiv);

// Скрываем основной контент страницы
document.body.style.visibility = 'hidden';

// Функция для имитации прогресса загрузки
var progress = 0;
var interval = setInterval(function() {
    progress += 5;
    progressBar.style.width = progress + '%';

    // Когда прогресс достигает 100%, останавливаем интервал
    if (progress >= 100) {
        clearInterval(interval);
    }
}, 150); // Прогресс обновляется каждые 150 миллисекунд

// Убираем эффект загрузки через 3 секунды
window.onload = function() {
    setTimeout(function() {
        // Прячем элемент загрузки
        var loadingElement = document.getElementById('loading');
        if (loadingElement) {
            loadingElement.style.display = 'none';
        }

        // Показываем основной контент страницы
        document.body.style.visibility = 'visible';
    }, 3000); // Задержка 3 секунды
};




mw.loader.using('mediawiki.util').then(function () {
    // Не выполнять скрипт на странице редактирования
    if (location.href.includes('action=edit')) return;

    // Поддерживаемые языки (как в PHP $this->languages)
    var supportedLanguages = ['ru', 'en'];

    // Определяем язык из браузера (Accept-Language)
    var userLangRaw = navigator.languages && navigator.languages.length
        ? navigator.languages[0]
        : navigator.language || navigator.userLanguage || 'en';

    var lang = userLangRaw.slice(0, 2).toLowerCase();

    // Если язык не поддерживается — по умолчанию 'en'
    var userLang = supportedLanguages.includes(lang) ? lang : 'en';

    function processLangBlocks(container) {
        container.innerHTML = container.innerHTML.replace(
            /\{ru\}([\s\S]*?)\{else\}([\s\S]*?)\{end\}/gi,
            function(match, ruText, enText) {
                return userLang === 'ru' ? ruText.trim() : enText.trim();
            }
        );
    }

    processLangBlocks(document.body);
});