Открыть меню
Переключить меню настроек
Открыть персональное меню
Вы не представились системе
Ваш IP-адрес будет виден всем, если вы внесёте какие-либо изменения.

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

Страница интерфейса MediaWiki
Нет описания правки
Нет описания правки
 
(не показаны 142 промежуточные версии 3 участников)
Строка 1: Строка 1:
const currentURL = window.location.href;
/* Загрузка лого морпехов */
$(document).ready(function() {
    var secondUrl = "https://spacestories.club/Marine_Corps";
 
    var secondLogoImgUrl = "https://spacestories.club/images/0/0d/CMlog.png";


function kerisarTest() {
    if ($('.second-mw-logo').length === 0) {
  console.log("Проверка консоли");
  const currentUrl = window.location.href;
  console.log("currentUrl", currentUrl);


  const jsTest = document.getElementById("jsTest");
        var $secondLogo = $('<a>', {
  console.log("jsTest", jsTest);
            href: secondUrl,
  const buttonTest = document.createElement('button');
            class: 'second-mw-logo citizen-cdx-button--size-large cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--icon-only cdx-button--weight-quiet',
  buttonTest.classList.add('testButtonJs');
            title: 'Перейти на заглавную страницу Marines Corps',
  buttonTest.textContent = "Привет, я кнопка. Пока я ничего не делаю";
        }).append(
  jsTest.appendChild(buttonTest);
            $('<img>', {
  const kerisarPicture = document.createElement('img');
                class: 'mw-logo-icon',
  kerisarPicture.setAttribute('src',
                src: secondLogoImgUrl,
    "https://thumb.cloud.mail.ru/weblink/thumb/xw1/LLmd/Qui7Xbp6g");
                alt: 'Второе лого',
  jsTest.appendChild(kerisarPicture);
                'aria-hidden': 'true',
 
                height: '32',
 
                width: '32'
  const iFrameFrontier = document.createElement('iframe');
            })
  iFrameFrontier.setAttribute('src',"https://arles.station14.ru/frontier-main/server/status");
        );
  jsTest.appendChild(iFrameFrontier);
 
  const iFrameStalker = document.createElement('iframe');
  iFrameStalker.setAttribute('src',"https://game.stalkers14.xyz/status");
  jsTest.appendChild(iFrameStalker);
 
 
  const iFrameWiki = document.createElement('iframe');
  iFrameWiki.setAttribute('src',"https://station14.ru/wiki/%D0%A0%D0%BE%D0%B1%D0%BE%D1%82%D0%BE%D1%82%D0%B5%D1%85%D0%BD%D0%B8%D0%BA%D0%B0");
  jsTest.appendChild(iFrameWiki);
 
 
  const scriptTest = document.createElement('script');
  scriptTest.setAttribute('src',"https://game.stalkers14.xyz/status");
  jsTest.appendChild(scriptTest);
 
}


function getServersInfo(connect, callback) {
        $('.mw-logo').after($secondLogo);
  const xhr = new XMLHttpRequest();
  xhr.open('GET', connect, true);
  xhr.onload = function() {
    if (xhr.status >= 200 && xhr.status < 300) {
      const data = JSON.parse(xhr.responseText);
      callback(null, data);
    } else {
      callback('Ошибка при выполнении запроса: ' + xhr.status, null);
     }
     }
  };
});
  xhr.onerror = function() {
    callback('Ошибка при выполнении запроса', null);
  };
  xhr.send();
}


function shangeServersInfo(serverObj, serverName) {
console.log(serverObj, serverName);
if (currentURL.includes("Kerisar")) {
      const serverStatusFrame = document.getElementById(serverName);
      //console.log("serverStatusFrame", serverStatusFrame);
     
      serverStatusFrame.querySelector(".serverInfoRoundSet").textContent = "#" + serverObj.round;
      if (serverObj.status === 0) {
      serverStatusFrame.querySelector(".serverStatusSet").textContent = "Лобби";
      }
      if (serverObj.status === 1) {
      serverStatusFrame.querySelector(".serverStatusSet").textContent = "Раунд идёт";
      }
      if (serverObj.status === 2) {
      serverStatusFrame.querySelector(".serverStatusSet").textContent = "Завершение";
      }
      serverStatusFrame.querySelector(".serverMapSet").textContent = serverObj.map;
      serverStatusFrame.querySelector(".serverTimeSet").textContent = serverObj.time;
      serverStatusFrame.querySelector(".serverPlayersSet").textContent = serverObj.players;
      serverStatusFrame.querySelector(".serverPresetSet").textContent = serverObj.preset;
    }
}


function standartServersInfo(connect, name) {
/* Аудиоплееры */
getServersInfo(connect, function(error, data) {
(function(){
     if (error) {
    var players = document.getElementsByClassName('audio-player');
      console.error(error); // Обработка ошибок
     for(var i=0;i<players.length;i++){
    } else {
        (function(p){
      //console.log("Ответ получен", data)
            var src = p.getAttribute('data-src');
      const serverInfo = {
            if(src){
      name: data.name,
                var audio = document.createElement('audio');
        round: data.round_id,
                audio.setAttribute('controls','controls');
        status: data.run_level,
                audio.setAttribute('preload','none');
        map: data.map,
                var source = document.createElement('source');
        time: new Date(data.round_start_time).toLocaleString(),
                source.setAttribute('src',src);
        players: data.players,
                source.setAttribute('type','audio/mpeg');
        preset: data.preset
                audio.appendChild(source);
      };
                p.appendChild(audio);
      shangeServersInfo(serverInfo, name);
            }
      //console.log(serverInfo);
        })(players[i]);
     }
     }
  });
})();
}


/* Подгрузка внешних CSS/JS */
(function(){
    if(typeof mw === 'undefined') return;


function standartServersInfoAll() {
    function getFilesFromUrl(param){
for (var i = 0; i < serversStatus.length; i++) {
        if(!param) return [];
standartServersInfo(serversStatus[i].connect, serversStatus[i].name);
        return param.split('|').map(function(file){ return file.trim(); });
}
    }
}


function customCSS(textCSS){
    function getBaseUrl(){
const styleSheet = document.createElement("style");
        var server = mw.config.get('wgServer').replace(/^http:/,'https:');
styleSheet.textContent = textCSS;
        var script = mw.config.get('wgScript');
//console.log(textCSS);
        return server + script + '?action=raw&ctype=text/';
    }
document.head.appendChild(styleSheet);
}


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


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


    function loadFiles(files){
if (cssEls.length > 0) {
        for(var i=0;i<files.length;i++){
            var url = getFileUrl(files[i]);
for (var i = 0; i < cssEls.length; i++) {
            if(url){
const textCSS = cssEls[i].textContent;
                var ext = files[i].split('.').pop().toLowerCase();
console.log(textCSS);
                mw.loader.load(url,'text/' + (ext==='js' ? 'javascript' : 'css'));
customCSS(textCSS);
            }
}
}
});
 
/*WikiEditor/Викификатор*/
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
  mw.loader.load(
    '//ru.wikipedia.org/w/index.php?title=MediaWiki:Gadget-wikificator.js&action=raw&ctype=text/javascript'
  );
}
var customizeToolbar = function() {
  $('#wpTextbox1').wikiEditor('addToToolbar', {
    'section': 'advanced',
    'group': 'format',
    'tools': {
      'wikify': {
        label: 'Викификатор',
        type: 'button',
        icon: '//upload.wikimedia.org/wikipedia/commons/0/06/Wikify-toolbutton.png',
        action: {
          type: 'callback',
          execute: function(context) {
            Wikify();
          }
         }
         }
      }
    }
  });
};
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
  mw.loader.using('user.options', function() {
    if (mw.user.options.get('usebetatoolbar')) {
      mw.loader.using('ext.wikiEditor.toolbar', function() {
        $(document).ready(customizeToolbar);
      });
     }
     }
  });
}


    mw.loader.using('mediawiki.util', function(){
        var params = mw.util.getParamValue('use');
        var files = getFilesFromUrl(params);
        loadFiles(files);
    });
})();


/**
/* Перенос page-info и цвет заголовков */
* Taken from https://wiki.ss220.space/index.php?title=MediaWiki:Common.js&oldid=35626
(function(){
*/
    var footerPlaces = document.getElementById('footer-places');
    var pageInfo = document.querySelector('.page-info');
    if(footerPlaces && pageInfo){
        footerPlaces.insertAdjacentElement('afterend', pageInfo.cloneNode(true));
        pageInfo.parentNode.removeChild(pageInfo);
    }


/* Variables for interface text used throughout the script, for ease of translating */
    var headerColorElement = document.querySelector('.headerColor');
var i18n = {
    if(headerColorElement){
    // Collapsible elements and page loader
        var content = headerColorElement.textContent.split('|');
    hideText: 'скрыть',
        if(content.length === 2){
    showText: 'показать',
            var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
   
            for(var hi=0; hi<headers.length; hi++){
    // Page loader
                var header = headers[hi],
     loadErrorTitle: 'Возникла ошибка при загрузке содержимого'
                    indicator = header.querySelector('.citizen-section-indicator'),
};
                    headline = header.querySelector('.mw-headline');
                if(!indicator || !headline) continue;
                if(header.classList.contains('citizen-section-heading--collapsed')){
                    indicator.style.cssText = 'background: black; box-shadow: unset;';
                } else {
                    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;';
                }
            }
        }
     }
})();


var mcw = window.mcw = {};
/* Sidebar для ролей */
(function(){
    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';
        }
    }
})();


/* Keep track of delegated events on dynamic content */
/* Хронология */
mcw.events = {};
(function(){
/* Fired whenever wiki content is added. (#mw-content-text, live preview, load page, etc.) */
    if(!window.jQuery) return;
mw.hook( 'wikipage.content' ).add( function( $wikipageContent ) {
    jQuery(function($){
/**
        $('.timeline-header').on('click', function(){
* Page loader
            $(this).next('.timeline-content').slideToggle();
*
        }).trigger('click');
* Allows a page to be downloaded and displayed on demand.
    });
* Use with Template:LoadPage and Template:LoadBox
})();
*/


( function() {
/* Галерея */
var $loadPage = $wikipageContent.find( '.load-page' );
(function(){
if ( !$loadPage.length ) {
    var root = document.getElementById('ss-art-gallery');
return;
    if(!root) return;
}
// We need the spinner to show loading is happening, but we don't want
// to have a delay while the module downloads, so we'll load this now,
// regardless of if something is clicked
mw.loader.load( 'jquery.spinner' );
// Create button starting with hide text
// Will be changed to the show text while calculating the maximum button size
var $buttonTemplate = $( '<span>' ).addClass( 'mw-editsection-like load-page-button' )
.append( '[ ', $( '<span>' ).addClass( 'jslink' ).text( i18n.hideText ), ' ]' );
var extractList = function( $contentContainer, listClass ) {
var $content = $contentContainer.find( '.mw-parser-output > ul > li > ul' ).children( ':not(.nbttree-inherited)' );
if ( listClass ) {
$content.addClass( listClass );
}
return $content;
};
$loadPage.each( function() {
var $body = $( this );
var page = $body.data( 'page' );
if ( !page ) {
return;
}
var template = $body.data( 'template' );
var treeview = $body.data( 'treeview' );
var treeviewClass = $body.data( 'treeviewclass' );
var $heading;
var $contentContainer;
var $content;
var $button = $buttonTemplate.clone();
var $buttonLink = $button.find( '.jslink' );
if ( treeview ) {
$heading = $body;
$contentContainer = $( '<div>' );
} else {
$heading = $body.children().first();
$contentContainer = $body.find( '.load-page-content' );
}
// Add the button
$heading.append( $button );
// Move the edit button to the right spot
$contentContainer.find( '.mw-editsection, .mw-editsection-like' ).insertAfter( $button );
// Find max button width, and set its min-width to it
var hideWidth = $button.width();
$buttonLink.text( i18n.showText );
var showWidth = $button.width();
if ( hideWidth !== showWidth ) {
$button.css( 'min-width', hideWidth > showWidth ? hideWidth : showWidth );
}
$buttonLink.click( function() {
if ( $body.hasClass( 'pageloader-contentloaded' ) ) {
if ( $buttonLink.text() === i18n.showText ) {
if ( treeview ) {
$content.insertAfter( $body );
} else {
$contentContainer.show();
}
$buttonLink.text( i18n.hideText );
} else {
if ( treeview ) {
$content.detach();
} else {
$contentContainer.hide();
}
$buttonLink.text( i18n.showText );
}
return;
}
// See if this was loaded elsewhere before making a request
var gotContent;
$( '.pageloader-contentloaded' ).each( function() {
var $fLoader = $( this );
if ( $fLoader.data( 'page' ) === page && $fLoader.data( 'pageloader-content' ) ) {
$contentContainer.html( $fLoader.data( 'pageloader-content' ) ).removeClass( 'noscript' );
mw.hook( 'wikipage.content' ).fire( $contentContainer );
if ( treeview ) {
$body.find( '.noscript' ).remove();
$content = extractList( $contentContainer, treeviewClass );
$content.insertAfter( $body );
}
$buttonLink.text( i18n.hideText );
$body.addClass( 'pageloader-contentloaded' );
gotContent = true;
return false;
}
} );
if ( gotContent ) {
return;
}
// Just in-case the spinner module is still not ready yet
var $spinner = $();
mw.loader.using( 'jquery.spinner', function() {
// $spinner will be false if the content somehow loaded before the module did
if ( $spinner ) {
$spinner = $.createSpinner().addClass( 'mw-editsection-like' )
.css( 'min-width', $button.css( 'min-width' ) );
$button.hide().after( $spinner );
}
} );
var requestData = {
action: 'parse',
prop: 'text'
};
if ( template ) {
requestData.page = page;
} else {
requestData.title = mw.config.get( 'wgPageName' );
requestData.text = '{' + '{:' + page + '}}';
}
new mw.Api().get( requestData ).done( function( data ) {
var html = data.parse.text['*'];
$contentContainer.html( html ).removeClass( 'noscript' );
// Resolve self-links
if ( template ) {
var curPage = '/' + mw.config.get( 'wgPageName' );
$contentContainer.find( 'a' ).each( function() {
var $link = $( this );
if ( $link.attr( 'href' ) === curPage ) {
$link.replaceWith( $( '<strong>' ).addClass( 'selflink' ).append( $link.contents() ) );
}
} );
html = $contentContainer.html();
}
$body.data( 'pageloader-content', html );
// Fire content hook on the new content, running all this stuff again and more :)
mw.hook( 'wikipage.content' ).fire( $contentContainer );
if ( treeview ) {
$body.find( '.noscript' ).remove();
$content = extractList( $contentContainer, treeviewClass );
$content.insertAfter( $body );
}
$spinner.remove();
$spinner = false;
$buttonLink.text( i18n.hideText );
$button.show();
$body.addClass( 'pageloader-contentloaded' );
} ).fail( function( _, error ) {
$spinner.remove();
$spinner = false;
$button.show();
var errorText = '';
if ( error.textStatus ) {
errorText = error.textStatus;
} else if ( error.error ) {
errorText = error.error.info;
}
mw.notify( errorText, { title: i18n.loadErrorTitle, autoHide: false } );
} );
} );
} );
}() );


/**
    function q(a,b){ return a.querySelector(b); }
* Element animator
    function qa(a,b){ return Array.prototype.slice.call(a.querySelectorAll(b)); }
*
* Will cycle the active class on any child elements
* within an element with the animated class.
*/
( function() {
if ( !mcw.animate ) {
mcw.animate = setInterval( function() {
$( '.animated' ).each( function() {
var $elem = $( this );
var $current = $elem.children( '.active' );
var $next = $current.nextAll( ':not(.skip):first' );
// Loop back to the start
if ( !$next.length ) {
$next = $elem.children( ':not(.skip):first' );
}
$current.removeClass( 'active' );
$next.addClass( 'active' );
} );
}, 2000 );
}
}() );


} );
    var chips = qa(root,'.ss-chip');


// SS220 import end
    function setFilter(val){
/*Код Аррр*/
        for(var ci=0; ci<chips.length; ci++){
 
            var c = chips[ci];
 
            var active = (c.getAttribute('data-filter')===val || (val==='all' && c.getAttribute('data-filter')==='all'));
/*Подгрузка внешних css js*/
            c.classList.toggle('ss-chip-active', active);
mw.loader.using('mediawiki.util', function () {
        }
    var files = mw.util.getParamValue('use'),
        userName = mw.config.get('wgUserName') || '', // Обрабатываем null
        FileRE = new RegExp('^(?:MediaWiki:|User:' + mw.util.escapeRegExp(userName) + '/)?[^&<>=%#]*\\.(js|css)$'),
        path = mw.config.get('wgServer').replace(/^http:/, 'https:') + mw.config.get('wgScript') + '?action=raw&ctype=text/';
 
    if (!files) return;


    $.each(files.split('|'), function (k, v) {
        var sections = qa(root,'.ss-section');
        var file = $.trim(v), match = FileRE.exec(file);
        for(var si=0; si<sections.length; si++){
        if (match) {
            var section = sections[si];
            switch (match[1]) {
            var cards = qa(section,'.ss-card');
                 case 'js':
            var visibleCount = 0;
                    mw.loader.load(path + 'javascript&title=' + encodeURIComponent(file), 'text/javascript');
            for(var cj=0; cj<cards.length; cj++){
                    break;
                var card = cards[cj];
                 case 'css':
                 var show = (val==='all' || val===card.getAttribute('data-artist'));
                    mw.loader.load(path + 'css&title=' + encodeURIComponent(file), 'text/css');
                 card.classList.toggle('ss-hidden', !show);
                    break;
                if(show) visibleCount++;
             }
             }
            section.style.display = (val==='all' || visibleCount>0)?'block':'none';
         }
         }
     });
     }
});


    for(var i=0;i<chips.length;i++){
        (function(ch){
            ch.addEventListener('click', function(){ setFilter(ch.getAttribute('data-filter')); });
        })(chips[i]);
    }
    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;
    }


/* Лого сайта */
    var images = qa(root,'.ss-card img');
var logoElement = document.getElementsByClassName('citizen-header__logo')[0];
    for(var ii=0; ii<images.length; ii++){
if (logoElement) {
        (function(img){
    logoElement.innerHTML = '<div class="logo1"><a href="https://spacestories.club/index.php?title=Заглавная страница" class="mw-logo citizen-header__button" title="Перейти на заглавную страницу"><img class="mw-logo-icon" src="/resources/assets/logo.png" alt="" aria-hidden="true" height="32" width="32"></a></div><div class="logo2"><a href="https://spacestories.club/index.php?title=Colonial_Marines" class="mw-logo citizen-header__button" title="Перейти на заглавную страницу CM"><img class="mw-logo-icon" src="/images/0/0d/CMlog.png" alt="" aria-hidden="true" height="32" width="32"></a></div>';
            img.style.cursor='zoom-in';
}
            img.addEventListener('click', function(e){
                e.preventDefault();
                var src = originalFromThumb(img.getAttribute('src')) || img.getAttribute('src');
                modalImg.setAttribute('src',src);
                modalImg.style.maxWidth='90vw';
                modalImg.style.maxHeight='90vh';
                modal.classList.add('open');
            });
        })(images[ii]);
    }


/* Перенос page-info в конец footer-places */
    function closeModal(){ modal.classList.remove('open'); }
var footerPlaces = document.getElementById('footer-places');
    modal.addEventListener('click', function(e){ if(e.target===modal||e.target.classList.contains('ss-modal-close')) closeModal(); });
var pageInfo = document.getElementsByClassName('page-info')[0];
     document.addEventListener('keydown', function(e){ if(e.key==='Escape') closeModal(); });
if (footerPlaces && pageInfo) {
})();
     footerPlaces.insertAdjacentHTML('afterEnd', pageInfo.innerHTML);
    pageInfo.innerHTML = '';
}


/* Логика цвета через headerColor */
/* Меню лора */
var headerColorElement = document.getElementsByClassName('headerColor')[0];
(function(){
if (headerColorElement) {
    var items = document.querySelectorAll('.custom-item');
    var isValidColor = function (color) {
    for(var mi=0; mi<items.length; mi++){
        var el = document.createElement('div');
        (function(item){
        el.style.backgroundColor = color;
            var icon = item.querySelector('.custom-icon');
        return !!el.style.backgroundColor;
            var linkEl = item.querySelector('a');
    };
            if(!linkEl) return;


    var headerContent = headerColorElement.innerHTML;
            var href = linkEl.getAttribute('href');
    var colorBorder = '', colorBtn = '', i = 0;
            item.style.cursor='pointer';


    while (headerContent[i] !== '|' && i < headerContent.length) {
            item.onclick = function(){ window.location.href = href; };
        colorBorder += headerContent[i++];
            item.onmousemove = function(e){
    }
                var rect = item.getBoundingClientRect();
    i++;
                var x = e.clientX - rect.left;
    while (i < headerContent.length) {
                var y = e.clientY - rect.top;
         colorBtn += headerContent[i++];
                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[mi]);
     }
     }
})();


    if (isValidColor(colorBorder) && isValidColor(colorBtn)) {
/* Химия */
        var headerRender = function (colorBorder, colorBtn) {
(function() {
            var headers = document.querySelectorAll('h1, h2, h3, h4, h5');
    if (typeof mw === 'undefined' || !window.document) return;
            for (var j = 0; j < headers.length; j++) {
   
                var header = headers[j];
    function initCollapse() {  
                 if (header.className === 'citizen-section-heading') {
        var headings = document.querySelectorAll('.chem-heading');  
                    var indicator = header.querySelector('.citizen-sections-enabled, .citizen-section-indicator');
        var hi = 0;  
                    var headline = header.querySelector('.mw-headline');
        var len = headings.length;  
                    if (indicator) {
        for (; hi < len; hi++) {  
                        indicator.style.background = colorBtn;
            (function(node) {
                        indicator.style.boxShadow = '0 0 20px 0px ' + colorBtn + 'cc';
                 if (node.getAttribute('data-chem-attached')) return;
                    }
                node.setAttribute('data-chem-attached', '1');  
                    if (headline) {
                node.style.cursor = 'pointer';  
                        headline.style.borderImage = 'linear-gradient(to right top, ' + colorBorder + ', black)';
                node.addEventListener('click', function() {  
                        headline.style.borderImageSlice = '1';
                    var kind = node.getAttribute('data-kind') || '';  
                     }
                    var wrapper = findWrapper(node, kind);  
                } else if (header.className === 'citizen-section-heading citizen-section-heading--collapsed') {
                     if (!wrapper) return;
                     var collapsedIndicator = header.querySelector('.citizen-sections-enabled, .citizen-section-heading--collapsed, .citizen-section-indicator');
                     var btn = node.querySelector('.collapse-btn');  
                     if (collapsedIndicator) {
                   
                         collapsedIndicator.style.background = 'black';
                     if (wrapper.classList.contains('collapsed')) {  
                         collapsedIndicator.style.boxShadow = 'unset';
                         wrapper.style.maxHeight = wrapper.scrollHeight + 'px';  
                    }
                         wrapper.classList.remove('collapsed');  
                }
                        wrapper.classList.add('expanded');
            }
                        if (btn) btn.textContent = 'свернуть';  
        };
                       
 
                        var cleanup = function() {
        headerRender(colorBorder, colorBtn);
                            wrapper.style.maxHeight = '';  
        document.body.addEventListener('click', function () {
                            wrapper.removeEventListener('transitionend', cleanup);  
            headerRender(colorBorder, colorBtn);
                        };
        });
                        wrapper.addEventListener('transitionend', cleanup);  
    }
                    } else {
}
                        var currentHeight = wrapper.scrollHeight;  
 
                        wrapper.style.maxHeight = currentHeight + 'px';  
/* Sidebar для ролей */
                        wrapper.offsetHeight;
var jobsContainer = document.getElementsByClassName('JobsTableContainer')[0];
                        wrapper.style.maxHeight = '0px';
if (jobsContainer) {
                        wrapper.classList.remove('expanded');
    var bodyContent = document.getElementById('bodyContent');
                        wrapper.classList.add('collapsed');  
    if (bodyContent) {
                        if (btn) btn.textContent = 'развернуть';  
        bodyContent.insertAdjacentHTML('beforebegin', jobsContainer.innerHTML);
                    }  
    }
                });  
    var jobTable = document.getElementById('IdJobsTableContainer1');
            })(headings[hi]);  
    if (jobTable) {
        }
        jobTable.id = 'IdJobsTableContainer2';
    }
    }
   
}
     function findWrapper(node, kind) {  
 
         var parent = node.parentNode;
/* Главное меню лора */
        if (!parent) return null;
document.querySelectorAll('.custom-item').forEach(function (item) {
        var wrappers = parent.querySelectorAll('.collapsible');  
    item.addEventListener('click', function () {
        var wi = 0;
        var link = item.querySelector('a');
        var wlen = wrappers.length;
        if (link) {
        for (; wi < wlen; wi++) {
            window.location.href = link.getAttribute('href');
             if (wrappers[wi].getAttribute('data-kind') === kind) {  
        }
                 return wrappers[wi];  
    });
             }  
});
        }
 
        return null;  
/* Хронология */
    }  
if (typeof $ === 'function') {
   
     $(document).ready(function () {
    if (document.readyState === 'complete' || document.readyState === 'interactive') {
         $('.timeline-header').click(function () {
        initCollapse();  
            var content = $(this).next('.timeline-content');
     } else {
             if (content.is(':visible')) {
        document.addEventListener('DOMContentLoaded', initCollapse);  
                 content.slideUp();
    }
             } else {
})();
                content.slideDown();
            }
        });
        $('.timeline-content').hide();
     });
}

Текущая версия от 22:29, 6 апреля 2026

/* Загрузка лого морпехов */
$(document).ready(function() {
    var secondUrl = "https://spacestories.club/Marine_Corps";

    var secondLogoImgUrl = "https://spacestories.club/images/0/0d/CMlog.png";

    if ($('.second-mw-logo').length === 0) {

        var $secondLogo = $('<a>', {
            href: secondUrl,
            class: 'second-mw-logo citizen-cdx-button--size-large cdx-button cdx-button--fake-button cdx-button--fake-button--enabled cdx-button--icon-only cdx-button--weight-quiet',
            title: 'Перейти на заглавную страницу Marines Corps',
        }).append(
            $('<img>', {
                class: 'mw-logo-icon',
                src: secondLogoImgUrl,
                alt: 'Второе лого',
                'aria-hidden': 'true',
                height: '32',
                width: '32'
            })
        );

        $('.mw-logo').after($secondLogo);
    }
});


/* Аудиоплееры */
(function(){
    var players = document.getElementsByClassName('audio-player');
    for(var i=0;i<players.length;i++){
        (function(p){
            var src = p.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);
                p.appendChild(audio);
            }
        })(players[i]);
    }
})();

/* Подгрузка внешних CSS/JS */
(function(){
    if(typeof mw === 'undefined') return;

    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){
        for(var i=0;i<files.length;i++){
            var url = getFileUrl(files[i]);
            if(url){
                var ext = files[i].split('.').pop().toLowerCase();
                mw.loader.load(url,'text/' + (ext==='js' ? 'javascript' : 'css'));
            }
        }
    }

    mw.loader.using('mediawiki.util', function(){
        var params = mw.util.getParamValue('use');
        var files = getFilesFromUrl(params);
        loadFiles(files);
    });
})();

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

    var headerColorElement = document.querySelector('.headerColor');
    if(headerColorElement){
        var content = headerColorElement.textContent.split('|');
        if(content.length === 2){
            var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
            for(var hi=0; hi<headers.length; hi++){
                var header = headers[hi],
                    indicator = header.querySelector('.citizen-section-indicator'),
                    headline = header.querySelector('.mw-headline');
                if(!indicator || !headline) continue;
                if(header.classList.contains('citizen-section-heading--collapsed')){
                    indicator.style.cssText = 'background: black; box-shadow: unset;';
                } else {
                    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;';
                }
            }
        }
    }
})();

/* Sidebar для ролей */
(function(){
    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';
        }
    }
})();

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

/* Галерея */
(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){
        for(var ci=0; ci<chips.length; ci++){
            var c = chips[ci];
            var active = (c.getAttribute('data-filter')===val || (val==='all' && c.getAttribute('data-filter')==='all'));
            c.classList.toggle('ss-chip-active', active);
        }

        var sections = qa(root,'.ss-section');
        for(var si=0; si<sections.length; si++){
            var section = sections[si];
            var cards = qa(section,'.ss-card');
            var visibleCount = 0;
            for(var cj=0; cj<cards.length; cj++){
                var card = cards[cj];
                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';
        }
    }

    for(var i=0;i<chips.length;i++){
        (function(ch){
            ch.addEventListener('click', function(){ setFilter(ch.getAttribute('data-filter')); });
        })(chips[i]);
    }
    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;
    }

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

    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(); });
})();

/* Меню лора */
(function(){
    var items = document.querySelectorAll('.custom-item');
    for(var mi=0; mi<items.length; mi++){
        (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[mi]);
    }
})();

/* Химия */
(function() { 
    if (typeof mw === 'undefined' || !window.document) return; 
    
    function initCollapse() { 
        var headings = document.querySelectorAll('.chem-heading'); 
        var hi = 0; 
        var len = headings.length; 
        for (; hi < len; hi++) { 
            (function(node) { 
                if (node.getAttribute('data-chem-attached')) return; 
                node.setAttribute('data-chem-attached', '1'); 
                node.style.cursor = 'pointer'; 
                node.addEventListener('click', function() { 
                    var kind = node.getAttribute('data-kind') || ''; 
                    var wrapper = findWrapper(node, kind); 
                    if (!wrapper) return; 
                    var btn = node.querySelector('.collapse-btn'); 
                    
                    if (wrapper.classList.contains('collapsed')) { 
                        wrapper.style.maxHeight = wrapper.scrollHeight + 'px'; 
                        wrapper.classList.remove('collapsed'); 
                        wrapper.classList.add('expanded'); 
                        if (btn) btn.textContent = 'свернуть'; 
                        
                        var cleanup = function() { 
                            wrapper.style.maxHeight = ''; 
                            wrapper.removeEventListener('transitionend', cleanup); 
                        }; 
                        wrapper.addEventListener('transitionend', cleanup); 
                    } else { 
                        var currentHeight = wrapper.scrollHeight; 
                        wrapper.style.maxHeight = currentHeight + 'px'; 
                        wrapper.offsetHeight; 
                        wrapper.style.maxHeight = '0px'; 
                        wrapper.classList.remove('expanded'); 
                        wrapper.classList.add('collapsed'); 
                        if (btn) btn.textContent = 'развернуть'; 
                    } 
                }); 
            })(headings[hi]); 
        } 
    } 
    
    function findWrapper(node, kind) { 
        var parent = node.parentNode; 
        if (!parent) return null; 
        var wrappers = parent.querySelectorAll('.collapsible'); 
        var wi = 0; 
        var wlen = wrappers.length; 
        for (; wi < wlen; wi++) { 
            if (wrappers[wi].getAttribute('data-kind') === kind) { 
                return wrappers[wi]; 
            } 
        } 
        return null; 
    } 
    
    if (document.readyState === 'complete' || document.readyState === 'interactive') { 
        initCollapse(); 
    } else { 
        document.addEventListener('DOMContentLoaded', initCollapse); 
    } 
})();