MediaWiki:Common.js

Страница интерфейса MediaWiki

Замечание: Возможно, после публикации вам придётся очистить кэш своего браузера, чтобы увидеть изменения.

  • Firefox / Safari: Удерживая клавишу Shift, нажмите на панели инструментов Обновить либо нажмите Ctrl+F5 или Ctrl+R (⌘+R на Mac)
  • Google Chrome: Нажмите Ctrl+Shift+R (⌘+Shift+R на Mac)
  • Internet Explorer / Edge: Удерживая Ctrl, нажмите Обновить либо нажмите Ctrl+F5
  • Opera: Нажмите Ctrl+F5.
/* =====================================================
  1. Хэллоуинская тема
   ===================================================== */
(function() {
    if (window.innerWidth < 1024 || /Mobi|Android|iPhone|iPad|iPod|Tablet/i.test(navigator.userAgent)) return;

    var body = document.body;
    var elements = [];

    var config = {
        leavesCount: 50,
        batsCount: 8,
        websCount: 5,
        pumpkinsCount: 3,
        leafIcons: ['🍂','🍁','🦇','🕸️'],
        pumpkinIcon: '🎃',
        leafMinSize: 14,
        leafMaxSize: 42,
        pumpkinMinSize: 24,
        pumpkinMaxSize: 36
    };

    function isDisabled() { return localStorage.getItem('halloweenThemeDisabled') === 'true'; }
    function isEnabled() { return !isDisabled(); }

    function createFragmentElements(count, createFn) {
        var frag = document.createDocumentFragment();
        for (var i = 0; i < count; i++) frag.appendChild(createFn(i));
        return frag;
    }

    function injectCSS() {
        if (document.getElementById('halloween-theme-css')) return;
        var style = document.createElement('style');
        style.id = 'halloween-theme-css';
        style.innerHTML = `
        .halloween-theme {
            --color-primary__h: 25;
            --color-primary__l: 40%;
            --primary-bg-color: #2a1a0f;
            --secondary-bg-color: #3b1f0b;
            --item-bg-color: #402715;
            --item-hover-bg-color: #5a2d0f;
            --border-color: #8b4513;
            --text-color: #ffe4b5;
            --hover-text-color: #fff8dc;
            --cf-bg-card: #3a1a0f;
            --cf-text-light: #ffdab9;
            --cf-text-muted: #c68642;
            --pumpkin-orange: #ff7518;
            --spooky-purple: #5a005a;
            --bat-black: #1b0c0c;
            --ghost-white: #f8f8ff;
            --zombie-green: #556b2f;
            --fire-color: #ff4500;
            --moon-glow: #f0f8ff;
        }
        .halloween-theme body, .halloween-theme .mw-body {
            background: radial-gradient(circle at top, #3b0f0f 0%, #1c0c0c 70%), linear-gradient(to bottom, #2a1a0f 0%, #3b1f0b 30%, #5a2d0f 60%, #ff7518 80%, #2c1c0f 100%);
            background-attachment: fixed;
            color: var(--text-color);
            transition: all 0.5s ease;
            min-height: 100vh;
            scroll-behavior: smooth;
        }
        .halloween-theme .mw-headline, .halloween-theme h2, .halloween-theme h3 {
            color: var(--pumpkin-orange);
            text-shadow: 2px 2px 6px #000, 0 0 15px rgba(255,117,24,0.4), 0 0 25px rgba(139,0,139,0.3);
            animation: spooky-glow 4s ease-in-out infinite alternate;
            position: relative;
        }
        @keyframes spooky-glow {
            0%, 100% { text-shadow: 2px 2px 6px #000, 0 0 15px rgba(255,117,24,0.4); }
            50% { text-shadow: 2px 2px 8px #000, 0 0 20px rgba(255,117,24,0.6), 0 0 30px rgba(90,0,90,0.4); }
        }
        .halloween-theme .halloween-leaves { position: fixed; top:0; left:0; width:100%; height:100%; pointer-events:none; overflow:hidden; z-index:998; }
        .halloween-theme .halloween-leaf { position:absolute; top:-2em; font-size:1.5em; animation: fall linear infinite; opacity:0; filter:drop-shadow(0 0 5px var(--pumpkin-orange)); transform-origin:center; }
        .halloween-theme .halloween-pumpkin { display:inline-block; animation: float 3s ease-in-out infinite, spooky-glow 4s ease-in-out infinite; filter: drop-shadow(0 0 8px var(--pumpkin-orange)); }
        @keyframes float { 0%{transform:translateY(0)} 50%{transform:translateY(-5px)} 100%{transform:translateY(0)} }
        .halloween-theme .halloween-bat { position:absolute; width:25px; height:15px; background:var(--bat-black); border-radius:50% 50% 20% 20%; animation: fly 12s linear infinite; }
        .halloween-theme .halloween-bat::after, .halloween-theme .halloween-bat::before { content:''; position:absolute; width:15px; height:5px; background:var(--bat-black); border-radius:50%; }
        .halloween-theme .halloween-bat::before { top:-5px; left:0; transform:rotate(30deg); }
        .halloween-theme .halloween-bat::after { top:-5px; right:0; transform:rotate(-30deg); }
        @keyframes fly { 0%{transform:translate(-50px,0) rotate(0deg);} 25%{transform:translate(200px,100px) rotate(15deg);} 50%{transform:translate(400px,50px) rotate(-15deg);} 75%{transform:translate(600px,150px) rotate(10deg);} 100%{transform:translate(800px,0) rotate(0deg);} }
        .halloween-theme .spider-web { position:absolute; width:30px; height:30px; background: radial-gradient(circle, transparent 30%, var(--border-color) 31%, transparent 32%), linear-gradient(45deg, transparent 45%, var(--border-color) 46%, transparent 47%), linear-gradient(-45deg, transparent 45%, var(--border-color) 46%, transparent 47%); opacity:0.3; pointer-events:none; animation:web-sway 6s ease-in-out infinite alternate; }
        @keyframes web-sway { 0%{transform:rotate(0deg)} 50%{transform:rotate(5deg)} 100%{transform:rotate(0deg)} }
        `;
        document.head.appendChild(style);
    }

    function initLeaves() {
        var leaves = document.createElement('div');
        leaves.className = 'halloween-leaves';
        var frag = createFragmentElements(config.leavesCount, function() {
            var leaf = document.createElement('span');
            leaf.className = 'halloween-leaf';
            leaf.innerHTML = config.leafIcons[Math.floor(Math.random() * config.leafIcons.length)];
            leaf.style.left = (Math.random() * 100) + '%';
            leaf.style.animationDelay = (Math.random() * 10) + 's';
            leaf.style.fontSize = (config.leafMinSize + Math.random() * (config.leafMaxSize - config.leafMinSize)) + 'px';
            leaf.style.opacity = Math.random() * 0.7 + 0.3;
            leaf.style.transform = 'rotate(' + (Math.random() * 360) + 'deg)';
            return leaf;
        });
        leaves.appendChild(frag);
        body.appendChild(leaves);
        for (var i = 0; i < leaves.childNodes.length; i++) elements.push(leaves.childNodes[i]);
    }

    function initPumpkins() {
        var heading = document.getElementById('firstHeading');
        if (!heading) return;
        for (var i = 0; i < config.pumpkinsCount; i++) {
            var pumpkin = document.createElement('span');
            pumpkin.className = 'halloween-pumpkin';
            pumpkin.innerHTML = config.pumpkinIcon;
            pumpkin.style.margin = '0 2px';
            pumpkin.style.fontSize = (config.pumpkinMinSize + Math.random() * (config.pumpkinMaxSize - config.pumpkinMinSize)) + 'px';
            heading.appendChild(pumpkin);
            (function(el) {
                var pos = 0, dir = 1;
                var interval = setInterval(function() {
                    pos += dir * 0.3;
                    if (pos > 5 || pos < 0) dir *= -1;
                    el.style.transform = 'translateY(' + pos + 'px)';
                }, 30);
                el._halloweenInterval = interval;
            })(pumpkin);
            elements.push(pumpkin);
        }
    }

    function initBats() {
        for (var i = 0; i < config.batsCount; i++) {
            var bat = document.createElement('div');
            bat.className = 'halloween-bat';
            bat.style.top = (Math.random() * 50) + 'vh';
            bat.style.left = (-50 + Math.random() * 100) + 'px';
            bat.style.animationDuration = (8 + Math.random() * 6) + 's';
            body.appendChild(bat);
            elements.push(bat);
        }
    }

    function initWebs() {
        for (var i = 0; i < config.websCount; i++) {
            var web = document.createElement('div');
            web.className = 'spider-web';
            web.style.top = (Math.random() * 80) + 'vh';
            web.style.left = (Math.random() * 90) + 'vw';
            web.style.transform = 'rotate(' + (Math.random() * 360) + 'deg)';
            body.appendChild(web);
            elements.push(web);
        }
    }

    function removeHalloween() {
        for (var i = 0; i < elements.length; i++) {
            var el = elements[i];
            if (el._halloweenInterval) clearInterval(el._halloweenInterval);
            if (el.parentNode) el.parentNode.removeChild(el);
        }
        elements = [];
        body.classList.remove('halloween-theme');
    }

    function styleButton(btn) {
        btn.style.position = 'fixed';
        btn.style.bottom = '10px';
        btn.style.right = '10px';
        btn.style.padding = '6px 12px';
        btn.style.background = 'var(--pumpkin-orange)';
        btn.style.color = 'var(--ghost-white)';
        btn.style.cursor = 'pointer';
        btn.style.borderRadius = '6px';
        btn.style.zIndex = 9999;
        btn.style.boxShadow = '0 0 8px var(--pumpkin-orange)';
        btn.style.marginTop = '4px';
    }

    function addButtons() {
        var btnDisable = document.createElement('div');
        var btnEnable = document.createElement('div');

        btnDisable.innerText = 'Отключить хэллоуинскую тему';
        btnEnable.innerText = 'Включить хэллоуинскую тему';

        styleButton(btnDisable);
        styleButton(btnEnable);

        btnEnable.style.display = 'none';

        btnDisable.addEventListener('click', function() {
            localStorage.setItem('halloweenThemeDisabled', 'true');
            removeHalloween();
            btnDisable.style.display = 'none';
            btnEnable.style.display = 'block';
        });

        btnEnable.addEventListener('click', function() {
            localStorage.removeItem('halloweenThemeDisabled');
            startHalloween();
            btnEnable.style.display = 'none';
            btnDisable.style.display = 'block';
        });

        body.appendChild(btnDisable);
        body.appendChild(btnEnable);
    }

    function startHalloween() {
        injectCSS();
        body.classList.add('halloween-theme');
        elements = [];
        initLeaves();
        initPumpkins();
        initBats();
        initWebs();
    }

    if (isEnabled()) startHalloween();
    addButtons();
})();




/* =====================================================
   2. Аудиоплееры
   ===================================================== */
$(function () {
    var players = document.getElementsByClassName('audio-player');
    for (var i = 0; i < players.length; i++) {
        var src = players[i].getAttribute('data-src');
        if (src) {
            var audio = document.createElement('audio');
            audio.setAttribute('controls', 'controls');
            audio.setAttribute('preload', 'none');
            var source = document.createElement('source');
            source.setAttribute('src', src);
            source.setAttribute('type', 'audio/mpeg');
            audio.appendChild(source);
            players[i].appendChild(audio);
        }
    }
});

/* =====================================================
   3. Подгрузка внешних CSS/JS файлов
   ===================================================== */
mw.loader.using('mediawiki.util', function() {
    function getFilesFromUrl(param) {
        if (!param) return [];
        return param.split('|').map(function(file) { return file.trim(); });
    }

    function getBaseUrl() {
        var server = mw.config.get('wgServer').replace(/^http:/, 'https:');
        var script = mw.config.get('wgScript');
        return server + script + '?action=raw&ctype=text/';
    }

    function isValidExtension(ext) { return ext === 'js' || ext === 'css'; }

    function getFileUrl(file) {
        var prefix = file.indexOf('MediaWiki:') === 0 ? 'MediaWiki:' : 'User:' + (mw.config.get('wgUserName') || '') + '/';
        var fullName = file.indexOf(':') > -1 ? file : prefix + file;
        var ext = file.split('.').pop().toLowerCase();
        if (!isValidExtension(ext)) {
            console.error('Недопустимое расширение файла:', file);
            return null;
        }
        var timestamp = new Date().getTime();
        return getBaseUrl() + (ext === 'js' ? 'javascript' : 'css') + '&title=' + encodeURIComponent(fullName) + '&_=' + timestamp;
    }

    function loadFiles(files) {
        files.forEach(function(file) {
            var url = getFileUrl(file);
            if (url) {
                var ext = file.split('.').pop().toLowerCase();
                mw.loader.load(url, 'text/' + (ext === 'js' ? 'javascript' : 'css'));
            }
        });
    }

    var params = mw.util.getParamValue('use');
    var files = getFilesFromUrl(params);
    loadFiles(files);
});

/* =====================================================
   4. Логотипы сайта
   ===================================================== */
(function() {
    function createLogo(url, imgSrc, title) {
        var container = document.createElement('div'),
            link = document.createElement('a'),
            img = document.createElement('img');

        link.className = 'mw-logo citizen-header__button';
        link.href = mw.util.getUrl(url);
        link.title = title;

        img.className = 'mw-logo-icon';
        img.src = imgSrc;
        img.alt = '';
        img.setAttribute('aria-hidden', 'true');
        img.width = 32;
        img.height = 32;

        link.appendChild(img);
        container.appendChild(link);
        return container;
    }

    var logoContainer = document.querySelector('.citizen-header__logo');
    if (logoContainer) {
        while (logoContainer.firstChild) logoContainer.removeChild(logoContainer.firstChild);

        var logo1 = createLogo('Заглавная_страница', mw.config.get('wgScriptPath') + '/resources/assets/logo.png', 'Перейти на заглавную страницу');
        logo1.className = 'logo1';
        var logo2 = createLogo('Marine_Corps', mw.config.get('wgScriptPath') + '/images/0/0d/CMlog.png', 'Перейти на CM');
        logo2.className = 'logo2';

        logoContainer.appendChild(logo1);
        logoContainer.appendChild(logo2);
    }
})();

/* =====================================================
   5. Перенос page-info и цвет заголовков
   ===================================================== */
var footerPlaces = document.getElementById('footer-places');
var pageInfo = document.querySelector('.page-info');
if (footerPlaces && pageInfo) {
    footerPlaces.insertAdjacentElement('afterend', pageInfo.cloneNode(true));
    pageInfo.remove();
}

var headerColorElement = document.querySelector('.headerColor');
if (headerColorElement) {
    var isValidColor = function(color) {
        var s = new Option().style;
        s.color = color;
        return s.color !== '';
    };

    var content = headerColorElement.textContent.split('|');
    if (content.length === 2 && isValidColor(content[0]) && isValidColor(content[1])) {
        var applyStyles = function() {
            var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
            for (var i = 0; i < headers.length; i++) {
                var header = headers[i],
                    indicator = header.querySelector('.citizen-section-indicator'),
                    headline = header.querySelector('.mw-headline');

                if (header.classList.contains('citizen-section-heading--collapsed')) {
                    if (indicator) indicator.style.cssText = 'background: black; box-shadow: unset;';
                } else if (indicator && headline) {
                    indicator.style.cssText = 'background: ' + content[1] + '; box-shadow: 0 0 20px 0px ' + content[1] + 'cc;';
                    headline.style.cssText = 'border-image: linear-gradient(to right top, ' + content[0] + ', black); border-image-slice: 1;';
                }
            }
        };
        applyStyles();
        document.body.addEventListener('click', applyStyles, false);
    }
}

/* =====================================================
   6. Sidebar для ролей
   ===================================================== */
var jobsContainer = document.querySelector('.JobsTableContainer');
if (jobsContainer && jobsContainer.innerHTML.trim()) {
    var bodyContent = document.getElementById('bodyContent');
    if (bodyContent) {
        bodyContent.insertAdjacentHTML('beforebegin', jobsContainer.innerHTML);
        var jobTable = document.getElementById('IdJobsTableContainer1');
        if (jobTable) jobTable.id = 'IdJobsTableContainer2';
    }
}

/* =====================================================
   7. Хронология
   ===================================================== */
if (window.jQuery) {
    jQuery(function($) {
        $('.timeline-header').on('click', function() {
            $(this).next('.timeline-content').slideToggle();
        }).trigger('click');
    });
}

/* =====================================================
   8. Галерея
   ===================================================== */
(function(){
    var root=document.getElementById('ss-art-gallery');
    if(!root) return;

    function q(a,b){return a.querySelector(b);}
    function qa(a,b){return Array.prototype.slice.call(a.querySelectorAll(b));}
    var chips=qa(root,'.ss-chip');

    function setFilter(val){
        chips.forEach(function(c){
            c.classList.toggle('ss-chip-active', c.getAttribute('data-filter')===val || (val==='all' && c.getAttribute('data-filter')==='all'));
        });

        qa(root,'.ss-section').forEach(function(section){
            var cards=qa(section,'.ss-card');
            var visibleCount=0;
            cards.forEach(function(card){
                var show=(val==='all'||val===card.getAttribute('data-artist'));
                card.classList.toggle('ss-hidden',!show);
                if(show) visibleCount++;
            });
            section.style.display=(val==='all'||visibleCount>0)?'block':'none';
        });
    }

    chips.forEach(function(ch){ ch.addEventListener('click', function(){ setFilter(ch.getAttribute('data-filter')) }); });
    setFilter('all');

    var modal=document.createElement('div');
    modal.className='ss-modal';
    modal.innerHTML='<div class="ss-modal-inner"><img class="ss-modal-img" alt=""/></div><div class="ss-modal-close" role="button">✖ Закрыть</div>';
    root.appendChild(modal);
    var modalImg=q(modal,'.ss-modal-img');

    function originalFromThumb(u){ 
        if(!u) return u;
        if(u.indexOf('/thumb/')>-1){
            var s=u.replace('/thumb/','/'); s=s.replace(/\/[^\/]*$/,''); return s;
        }
        return u;
    }

    qa(root,'.ss-card img').forEach(function(img){
        img.style.cursor='zoom-in';
        img.addEventListener('click',function(e){
            e.preventDefault();
            var src=originalFromThumb(img.getAttribute('src'));
            modalImg.setAttribute('src',src||img.getAttribute('src'));
            modalImg.style.maxWidth='90vw';
            modalImg.style.maxHeight='90vh';
            modal.classList.add('open');
        });
    });

    function closeModal(){ modal.classList.remove('open'); }
    modal.addEventListener('click',function(e){ if(e.target===modal||e.target.classList.contains('ss-modal-close')) closeModal(); });
    document.addEventListener('keydown',function(e){ if(e.key==='Escape') closeModal(); });
})();

/* =====================================================
   9. Меню лора
   ===================================================== */
(function() {
    var items = document.querySelectorAll('.custom-item');

    for (var i = 0; i < items.length; i++) {
        (function(item) {
            var icon = item.querySelector('.custom-icon');
            var linkEl = item.querySelector('a');
            if (!linkEl) return;

            var href = linkEl.getAttribute('href');
            item.style.cursor = 'pointer';

            item.onclick = function() { window.location.href = href; };
            item.onmousemove = function(e) {
                var rect = item.getBoundingClientRect();
                var x = e.clientX - rect.left;
                var y = e.clientY - rect.top;
                var moveX = (x - rect.width/2) * 0.02;
                var moveY = (y - rect.height/2) * 0.02;
                item.style.backgroundPosition = (50 + moveX) + '% ' + (50 + moveY) + '%';
                if(icon) icon.style.transform = 'translateY(-8px) scale(1.08)';
                var hue = Math.round((x / rect.width) * 360);
                item.style.boxShadow = 
                    '0 0 15px hsla(' + hue + ', 100%, 60%, 0.7), ' +
                    '0 0 30px hsla(' + ((hue+30)%360) + ', 100%, 50%, 0.4), ' +
                    '0 8px 20px rgba(0,0,0,0.5)';
            };
            item.onmouseleave = function() {
                item.style.backgroundPosition = '50% 50%';
                if(icon) icon.style.transform = 'translateY(0) scale(1)';
                item.style.boxShadow = '0 4px 10px rgba(0,0,0,0.3)';
            };
        })(items[i]);
    }
})();

/* =====================================================
   10. Страница Данте
   ===================================================== */
mw.loader.using('mediawiki.util', function() {
    var tabs = document.querySelectorAll('.nt-tab');
    var contents = document.querySelectorAll('.nt-tab-content');

    for (var i=0;i<tabs.length;i++){
        tabs[i].onclick = function(){
            for(var j=0;j<tabs.length;j++){
                tabs[j].className = tabs[j].className.replace(' active','');
                contents[j].className = contents[j].className.replace(' active','');
            }
            this.className += ' active';
            var target = document.getElementById(this.getAttribute('data-target'));
            if(target) target.className += ' active';
        };
    }

    var rows = document.querySelectorAll('.scan-row');
    for(var k=0;k<rows.length;k++){
        (function(i){ setTimeout(function(){ rows[i].className += ' visible'; }, i*200); })(k);
    }

    var dossier = document.querySelector('.nt-dossier');
    if(dossier) setTimeout(function(){ dossier.style.opacity = 1; }, 200);

    var tabsContainer = document.querySelector('.nt-tabs');
    if(tabsContainer) setTimeout(function(){ tabsContainer.style.opacity = 1; }, 400);
});