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

Материал из Space Station 14 Вики
Нет описания правки
(чтобы снова их вернуть)
 
(не показано 159 промежуточных версий 4 участников)
Строка 1: Строка 1:
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
const currentURL = window.location.href;
var tooltips = {
 
     debug: false,
const serversStatus = [
      
  {
     api: false,
     name: "main",
     types: [],
     connect: "https://game2.station14.ru/main/server/status"
     classes: ['basic-tooltip', 'advanced-tooltip'],
  },
     advancedCounter: 1,
  {
      
     name: "nova",
     events: [],
     connect: "https://game2.station14.ru/nova/server/status"
     timeouts: [],
  },
      
  {
     offsetX: 20,
     name: "athara",
     offsetY: 20,
    connect: "https://game2.station14.ru/athara/server/status"
     waitForImages: false,
  },
     noCSS: false,
  {
      
     name: "solaris",
    flip: false,
     connect: "https://game2.station14.ru/solaris/server/status"
      
  },
     init: function() {
  {
         if($(document.body).hasClass('mw-special-InfoboxBuilder')) return;
     name: "echo",
        if(location.search.search(/ttdebug=(1|[Tt]rue)/) != -1 || (typeof tooltips_debug != 'undefined' && tooltips_debug)) tooltips.debug = true;
     connect: "https://game2.station14.ru/echo/server/status"
        var href = (new mw.Uri($('link[rel="canonical"]').attr('href'))).path;
  },
        if(typeof href == 'undefined' || !href) {
  {
            console.log('Tooltips: script couldn\'t find required  link[rel="canonical"]  tag');
     name: "elysium",
            tooltips.disabled = true;
     connect: "https://game2.station14.ru/elysium/server/status"
            return false;
  },
        }
  {
        href = href.split('/wiki/');
     name: "nebula",
        tooltips.api = href[0]+'/api.php?format=json&action=parse&disablelimitreport=true&prop=text&title='+href[1];
     connect: "https://game2.station14.ru/nebula/server/status"
        if(mw.util.getParamValue('uselang')) tooltips.api += '&uselang='+mw.util.getParamValue('uselang');
  },
// Cache tooltip contents on the CDN for 10 minutes for anonymous users
  {
tooltips.api += '&maxage=600&smaxage=600'
     name: "wl",
         tooltips.api += '&text=';
     connect: "https://game2.station14.ru/wl/server/status"
  },
  {
  name: "frontier",
  connect: "https://arles.station14.ru/frontier-main/server/status"
  },
  {
  name: "marines",
  connect: "https://game1.station14.ru/marines-main/server/status"
  },
  {
  name:"stalker",
  connect: "https://game.stalkers14.xyz/status"
  }
];
 
function zIndexPosition() {
     var z_index = 100;
     $(".z_index_position div").each(function(index, domEl){
         $(domEl).css({"z-index": z_index})
        z_index--;
    })
}
 
function kerisarTest() {
  console.log("Проверка консоли");
  const currentUrl = window.location.href;
  console.log("currentUrl", currentUrl);
 
  const jsTest = document.getElementById("jsTest");
  console.log("jsTest", jsTest);
  const buttonTest = document.createElement('button');
  buttonTest.classList.add('testButtonJs');
  buttonTest.textContent = "Привет, я кнопка. Пока я ничего не делаю";
  jsTest.appendChild(buttonTest);
  const kerisarPicture = document.createElement('img');
  kerisarPicture.setAttribute('src',
    "https://thumb.cloud.mail.ru/weblink/thumb/xw1/LLmd/Qui7Xbp6g");
  jsTest.appendChild(kerisarPicture);
 
 
  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) {
  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) {
    if (error) {
      console.error(error); // Обработка ошибок
    } else {
      //console.log("Ответ получен", data)
      const serverInfo = {
      name: data.name,
        round: data.round_id,
        status: data.run_level,
        map: data.map,
        time: new Date(data.round_start_time).toLocaleString(),
        players: data.players,
         preset: data.preset
      };
      shangeServersInfo(serverInfo, name);
      //console.log(serverInfo);
    }
  });
}
 
 
function standartServersInfoAll() {
for (var i = 0; i < serversStatus.length; i++) {
standartServersInfo(serversStatus[i].connect, serversStatus[i].name);
}
}
 
 
$(document).ready(function() {
if (currentURL.includes("Kerisar")) {
kerisarTest();
standartServersInfoAll();
}
if (document.querySelector(".z_index_position")) {
        zIndexPosition();
          
          
        tooltips.types['basic-tooltip'] = {};
}
        tooltips.types['advanced-tooltip'] = {};
});
       
 
        if(!tooltips.config()) {
/*WikiEditor/Викификатор*/
            console.log('Tooltips: missing config');
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
             tooltips.disabled = true;
  mw.loader.load(
            return false;
    '//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();
          }
         }
         }
       
      }
        var content = $('#WikiaMainContent');
    }
        if(!content.length) content = $('#mw-content-text');
  });
       
};
        if(!tooltips.noCSS) {
if ($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
            var cssImport = importArticle({
  mw.loader.using('user.options', function() {
                type: 'style',
    if (mw.user.options.get('usebetatoolbar')) {
                article: 'u:dev:MediaWiki:Tooltips.css'
      mw.loader.using('ext.wikiEditor.toolbar', function() {
            });
         $(document).ready(customizeToolbar);
            if (Array.isArray(cssImport)) {
      });
                // MW 1.19
     }
                $(cssImport).prependTo('head');
  });
            } else {
}
                // UCP
 
                cssImport.then(function () {
 
                    var expectedSource = mw.loader.moduleRegistry['u:dev:MediaWiki:Tooltips.css'].style.css[0];
/**
                    for (var node = document.querySelector('head > meta[name="ResourceLoaderDynamicStyles"]').previousElementSibling; node.tagName === 'STYLE'; node = node.previousElementSibling) {
* Taken from https://wiki.ss220.space/index.php?title=MediaWiki:Common.js&oldid=35626
                        if (node.textContent === '\n' + expectedSource) {
*/
                            document.head.prepend(node);
 
                            return;
/* Variables for interface text used throughout the script, for ease of translating */
                        }
var i18n = {
                    }
     // Collapsible elements and page loader
                    throw new Error('WTF? Failed to find RL-inserted style!');
     hideText: 'скрыть',
                });
     showText: 'показать',
            }
      
        }
     // Page loader
       
    loadErrorTitle: 'Возникла ошибка при загрузке содержимого'
        if($('#tooltip-wrapper').length === 0) $('<div id="tooltip-wrapper" class="WikiaArticle"></div>').appendTo(document.body);
        if($('#tooltip-storage').length === 0) $('<div id="tooltip-storage" class="WikiaArticle"></div>').append('<div class="main-tooltip tt-basic-tooltip" id="tooltip-basic-tooltip">Lorem ipsum dolor sit amet</div>').appendTo(content);
       
        $('#tooltip-wrapper')
            .css({'margin':'0px','position':'fixed','height':'auto','min-height':'0','z-index': 6000000,'font-size':'14px'})
            .hide();
       
        $('#tooltip-storage')
            .css({'height':'0px','min-height':'0','visibility':'hidden','overflow':'hidden','position':'static','font-size':'14px'});
           
       
        $('#tooltip-basic-tooltip').data('type', 'basic-tooltip');
       
        tooltips.applyTooltips(document);
       
        mw.hook('wikipage.content').add(function(elem) {
            tooltips.applyTooltips($(elem));
        });
       
        if(typeof tooltips.events == 'string') tooltips.events = [tooltips.events];
        for(var x=0; x<tooltips.events.length; x++) { $(window).on(tooltips.events[x], function(ev, elem) { tooltips.applyTooltips(elem || this) }) }
       
        if(tooltips.debug) {
            $('#tooltip-wrapper').css({'background-color':'rgba(255,0,0,0.2)'});
            $('#tooltip-storage').css({'background-color':'rgba(0,255,0,0.2)','height':'500px','overflow-y':'scroll','visibility':'visible'});
        }
    },
    config: function() {
        if(typeof tooltips_list != 'undefined') {
            $(tooltips_list).each(function(i, v) { tooltips.addType(v) });
        }
        if(typeof tooltips_config == 'object') {
            tooltips.offsetX = tooltips_config.offsetX || tooltips.offsetX;
            tooltips.offsetY = tooltips_config.offsetY || tooltips.offsetY;
            tooltips.waitForImages = (tooltips_config.waitForImages || tooltips.waitForImages) && true;
            tooltips.noCSS = tooltips_config.noCSS || tooltips.noCSS;
            tooltips.events = tooltips_config.events || tooltips.events;
        }
       
        return true;
    },
    applyTooltips: function(elem) {
        $(elem).find('.'+tooltips.classes.join(', .')).each(function() {
            $this = $(this);
            if($this.hasClass('tooltips-init-complete')) return;
           
            $this.find('*').removeAttr('title');
            $this.mouseover(tooltips.handlers.mouseOver);
            $this.mouseout(tooltips.handlers.mouseOut);
            $this.mousemove(tooltips.handlers.mouseMove);
           
            $this.data('tooltip-contents', $(this).attr('title'));
            $this.removeAttr('title');
           
            tooltips.advancedTooltip($this);
           
            $(this).addClass('tooltips-init-complete');
        });
    },
    advancedTooltip: function(elem) {
         elem = $(elem);
        if(!elem.hasClass('advanced-tooltip')) return;
        var tips = elem.find('.tooltip-contents');
        if(!tips.length) return;
        var tip = $('<div class="main-tooltip tt-advanced-tooltip"></div>').attr('id', 'tooltip-advanced-tooltip-'+tooltips.advancedCounter).appendTo('#tooltip-storage').data('type', 'advanced-tooltip').append($(tips[0]).contents()).each(tooltips.calcSize);
        tips.remove();
        elem.data('tooltip-id-advanced-tooltip', tooltips.advancedCounter);
        tooltips.advancedCounter++;
     },
    addType: function(tt) {
        if(typeof tooltips.types[tt.classname] == 'undefined') {
            var obj = {};
           
            if(typeof tt.parse == 'string' || typeof tt.parse == 'function') var parse = tt.parse; else var parse = false;
            if(typeof tt.text == 'string' || typeof tt.text == 'function') var text = tt.text; else var text = false;
           
            if(parse) {
                obj.text = parse;
                obj.parse = true;
            } else if(text) {
                obj.text = text;
                obj.parse = false;
            } else return;
           
            if(typeof obj.text == 'string') obj.parameters = tooltips.getParameters(obj.text); else obj.parameters = [];
           
            if(typeof tt.delay == 'string' || typeof tt.delay == 'number') obj.delay = parseInt(tt.delay); else obj.delay = false;
            if(typeof tt.onParsed == 'function') obj.onParsed = tt.onParsed;
            if(typeof tt.onShow == 'function') obj.onShow = tt.onShow;
            if(typeof tt.onHide == 'function') obj.onHide = tt.onHide;
           
            tooltips.types[tt.classname] = obj;
            if(tooltips.classes.indexOf(tt.classname) == -1) tooltips.classes.push(tt.classname);
        } else {
            if(typeof tt.delay == 'string' || typeof tt.delay == 'number') tooltips.types[tt.classname].delay = parseInt(tt.delay);
            if(typeof tt.onParsed == 'function') tooltips.types[tt.classname].onParsed = tt.onParsed;
            if(typeof tt.onShow == 'function') tooltips.types[tt.classname].onShow = tt.onShow;
            if(typeof tt.onHide == 'function') tooltips.types[tt.classname].onHide = tt.onHide;
        }
    },
    getParameters: function(text) {
        var list = [];
        var matches = text.match(/<#\s*[a-z0-9_\-]+?\s*#>/gi);
        if(matches) {
            for(var x=0; x<matches.length; x++) {
                list.push(/<#\s*([a-z0-9_\-]+?)\s*#>/i.exec(matches[x])[1]);
            }
        }
        return list;
    },
    getAPI: function(text) {
        return tooltips.api+encodeURIComponent(text);
    },
    getText: function(type, elem) {
        if(typeof tooltips.types[type].text == 'function') {
            var text = tooltips.types[type].text($(elem)[0]);
        } else {
            var text = tooltips.types[type].text;
            for(var x=0; x<tooltips.types[type].parameters.length; x++) {
                var param = tooltips.types[type].parameters[x];
                var value = $(elem).data(param);
                if(typeof value == 'undefined') value = '';
                var rx = new RegExp('<#\\s*'+param.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&")+'\\s*#>', 'g');
                text = text.replace(rx, value);
            }
        }
        return text;
    },
    getTooltip: function(type, elem) {
        elem = $(elem);
        if(elem.data('tooltip-id-'+type)) return $('#tooltip-'+type+'-'+elem.data('tooltip-id-'+type));
       
        var text = tooltips.getText(type, elem);
        var id = tooltips.hash(text);
        elem.data('tooltip-id-'+type, id);
       
        var tip = $('#tooltip-'+type+'-'+elem.data('tooltip-id-'+type));
        if(tip.length) return tip;
       
        tip = $('<div class="main-tooltip"></div>').attr('id', 'tooltip-'+type+'-'+id).appendTo('#tooltip-storage').data('type', type).addClass('tt-'+type);
       
        tooltips.wrapperPosition(tooltips.lastKnownMousePos[0], tooltips.lastKnownMousePos[1]);
        tooltips.sameWidth();
       
        if(!tooltips.types[type].parse) {
            tip.html(text).each(tooltips.calcSize);
            tooltips.wrapperPosition(tooltips.lastKnownMousePos[0], tooltips.lastKnownMousePos[1]);
            tooltips.sameWidth();
        } else {
            tip.addClass('tooltip-loading');
            var api = tooltips.getAPI(text);
            if(tooltips.debug) tip.html('<pre style="padding:2px 3px;font-size:11px;">'+api+'</pre>');
            tip.attr('title', api);
            $.ajax({
                url: api,
                dataType: 'json',
                context: tip,
                success: function(data, textStatus, jqXHR) {
                    $(this).html(data['parse']['text']['*']).each(tooltips.calcSize);
                    tooltips.wrapperPosition(tooltips.lastKnownMousePos[0], tooltips.lastKnownMousePos[1]);
                    tooltips.sameWidth();
                    var images = $(this).find('img');
                    images.fadeTo(0, 0).one('load', function() {
                        if(tooltips.waitForImages) {
                            $(this).fadeTo(0,1);
                            $(this).addClass('image-loaded');
                            tip = $(this).closest('.main-tooltip');
                            if(tip.find('img').length == tip.find('img.image-loaded').length) {
                                tip.removeClass('tooltip-loading').each(tooltips.calcSize);
                                tooltips.wrapperPosition(tooltips.lastKnownMousePos[0], tooltips.lastKnownMousePos[1]);
                                tooltips.sameWidth();
                            }
                        } else $(this).fadeTo(100,1);
                    });
                    if(tooltips.waitForImages) {
                        if(images.length === 0) {
                            $(this).removeClass('tooltip-loading').each(tooltips.calcSize);
                        }
                    } else {
                        $(this).removeClass('tooltip-loading').each(tooltips.calcSize);
                    }
                    var type = $(this).data('type') || false;
                    if(type && typeof tooltips.types[type].onParsed == 'function') {
                        tooltips.types[type].onParsed.call(this);
                        tip.each(tooltips.calcSize);
                    }
                    if($(this).find('a.new').length > 0) $(this).addClass('has-redlinks');
                    tooltips.wrapperPosition(tooltips.lastKnownMousePos[0], tooltips.lastKnownMousePos[1]);
                    tooltips.sameWidth();
                }
            });
        }
        return tip;
    },
     getBasicTooltip: function(elem) {
        return $("#tooltip-basic-tooltip").html(mw.html.escape($(elem).data('tooltip-contents')).replace(/\\n/g,'<br />')).each(tooltips.calcSize);
     },
    getAdvancedTooltip: function(elem) {
        return $("#tooltip-advanced-tooltip-"+$(elem).data('tooltip-id-advanced-tooltip'));
    },
     getTooltips: function(elem) {
        elem = $(elem);
        var classes = elem.attr('class').split(' ');
        var tips = [];
        for(var i=0;i<classes.length;i++) {
            var tip = false;
            if(classes[i] == 'advanced-tooltip') tip = tooltips.getAdvancedTooltip(elem);
            else if(classes[i] == 'basic-tooltip') tip = tooltips.getBasicTooltip(elem);
            else if(typeof tooltips.types[classes[i]] != 'undefined') tip = tooltips.getTooltip(classes[i], elem);
            if(tip) tips.push(tip[0]);
        }
        return $(tips);
     },
     setOwnWidth: function() {
        $this = $(this);
        if(typeof $this.data('width') != 'undefined') $this.css('width', $this.data('width')+'px');
        else $this.css('width', '');
    },
    calcSize: function() {
        $this = $(this);
        $this.css('position', 'absolute');
        var temp = $this.css('width');
        $this.css('width', '');
        $this.data('width', parseFloat(window.getComputedStyle($this[0]).width));
        $this.data('height', parseFloat(window.getComputedStyle($this[0]).height));
        $this.data('outerwidth', $this.outerWidth(true));
        $this.data('outerheight', $this.outerHeight(true));
        $this.css('width', $this.data('width')+'px');
        $this.css('position', '');
        $this.css('width', temp);
    },
    sameWidth: function() {
        if($("#tooltip-wrapper").find('.main-tooltip').length == 1) {
            $("#tooltip-wrapper").find('.main-tooltip').each(tooltips.setOwnWidth);
        } else {
            var width = 0;
            $("#tooltip-wrapper").find('.main-tooltip').each(function() { width = Math.max(width, $(this).data('width') || 0); });
            $("#tooltip-wrapper").find('.main-tooltip').each(function() { $(this).css('width', width+'px'); });
        }
    },
    wrapperPosition: function(mouseX, mouseY) {
        var tipH = parseInt($("#tooltip-wrapper").css('padding-top')) + parseInt($("#tooltip-wrapper").css('padding-bottom'));
        var tipW = 0;
        var barH = $('#WikiaBarWrapper').height();
     
        $("#tooltip-wrapper").find('.main-tooltip').each( function(){ if(typeof $(this).data('outerheight') != 'undefined') tipH += $(this).data('outerheight'); });
        $("#tooltip-wrapper").find('.main-tooltip').each( function(){ if(typeof $(this).data('outerwidth') != 'undefined') tipW = Math.max(tipW, $(this).data('outerwidth') + parseInt($("#tooltip-wrapper").css('padding-left')) + parseInt($("#tooltip-wrapper").css('padding-right'))); });
       
        var spaceTop = mouseY - tooltips.offsetY;
        var spaceLeft = mouseX - tooltips.offsetX;
        var spaceRight = $(window).width() - mouseX - tooltips.offsetX;
        var spaceBottom = $(window).height() - barH - mouseY - tooltips.offsetY;
       
        var coordX = mouseX + tooltips.offsetX;
        var coordY = mouseY + tooltips.offsetY;
       
        if(spaceRight < tipW && spaceBottom < tipH) {
            if(spaceLeft >= tipW && tooltips.flip != 'h') {
                coordX = mouseX - tipW - tooltips.offsetX;
                tooltips.flip = 'v';
            } else if(spaceTop >= tipH) {
                coordY = mouseY - tipH - tooltips.offsetY;
                tooltips.flip = 'h';
            } else {
                coordX = mouseX - tipW - tooltips.offsetX;
                coordY = mouseY - tipH - tooltips.offsetY;
                tooltips.flip = 'vh';
            }
        } else {
            tooltips.flip = false;
        }
        if ($("#tooltip-wrapper").css('position') == 'fixed') {
            coordX = coordX-$(window).scrollLeft();
            coordY = coordY-$(window).scrollTop();
           
            coordX = Math.min(coordX, $(window).width() - tipW);
            coordY = Math.min(coordY, $(window).height() - tipH - barH);
        } else {
            coordX = Math.min(coordX, $(window).width() - tipW);
            coordY = Math.min(coordY, $(window).height() - tipH - barH + $(window).scrollTop());
        }
        $("#tooltip-wrapper").css({left: coordX + 'px', top: coordY + 'px'});
    },
    handlers: {
        mouseOver: function(e) {
            tooltips.lastKnownMousePos = [e.pageX, e.pageY];
            tooltips.wrapperPosition(e.pageX, e.pageY);
           
            var tips = tooltips.getTooltips(this);
            $("#tooltip-wrapper").prepend(tips).show();
            tooltips.sameWidth();
           
            var handle = this;
            tips.each(function() {
                var $this = $(this);
                var type = $(this).data('type') || false;
               
                $this.show();
                $(window).trigger('scroll');// trigger image lazy loader
                if(type && typeof tooltips.types[type] != 'undefined' && tooltips.types[type].delay) {
                    $this.hide();
                    tooltips.timeouts[$(this).attr('id')] = setTimeout(function(){
                        $this.show();
                        if(type && typeof tooltips.types[type].onShow == 'function') tooltips.types[type].onShow.call($this[0], handle);
                    }, tooltips.types[type].delay);
                } else if(type && typeof tooltips.types[type].onShow == 'function') tooltips.types[type].onShow.call(this, handle);
            });
        },
        mouseOut: function(e) {
            tooltips.lastKnownMousePos = [e.pageX, e.pageY];
            tooltips.wrapperPosition(e.pageX, e.pageY);
           
            var handle = this;
            $("#tooltip-wrapper").hide();
            $("#tooltip-wrapper").find('.main-tooltip').appendTo('#tooltip-storage').each(function() {
                var type = $(this).data('type') || false;
                if(type && typeof tooltips.types[type].onHide == 'function') tooltips.types[type].onHide.call(this, handle);
                $(this).show();
                clearTimeout(tooltips.timeouts[$(this).attr('id')]);
                delete tooltips.timeouts[$(this).attr('id')];
            });
        },
        mouseMove: function(e) {
            tooltips.lastKnownMousePos = [e.pageX, e.pageY];
            tooltips.wrapperPosition(e.pageX, e.pageY);
        },
    },
    hash: function(text) {
        /* Source: https://archive.is/nq2F9 */
        var hash = 0, i, char;
        if (text.length === 0) return hash;
        for (i = 0, l = text.length; i < l; i++) {
            char  = text.charCodeAt(i);
            hash  = ((hash<<5)-hash)+char;
            hash |= 0; // Convert to 32bit integer
        }
        return hash;
    },
};
};
$(tooltips.init);
 
var mcw = window.mcw = {};
 
/* Keep track of delegated events on dynamic content */
mcw.events = {};
/* Fired whenever wiki content is added. (#mw-content-text, live preview, load page, etc.) */
mw.hook( 'wikipage.content' ).add( function( $wikipageContent ) {
/**
* Page loader
*
* Allows a page to be downloaded and displayed on demand.
* Use with Template:LoadPage and Template:LoadBox
*/
 
( function() {
var $loadPage = $wikipageContent.find( '.load-page' );
if ( !$loadPage.length ) {
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 } );
} );
} );
} );
}() );
 
/**
* Element animator
*
* 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 );
}
}() );
 
} );
 
// SS220 import end

Текущая версия от 16:51, 2 июля 2024

const currentURL = window.location.href;

const serversStatus = [
  {
    name: "main",
    connect: "https://game2.station14.ru/main/server/status"
  },
  {
    name: "nova",
    connect: "https://game2.station14.ru/nova/server/status"
  },
  {
    name: "athara",
    connect: "https://game2.station14.ru/athara/server/status"
  },
  {
    name: "solaris",
    connect: "https://game2.station14.ru/solaris/server/status"
  },
  {
    name: "echo",
    connect: "https://game2.station14.ru/echo/server/status"
  },
  {
    name: "elysium",
    connect: "https://game2.station14.ru/elysium/server/status"
  },
  {
    name: "nebula",
    connect: "https://game2.station14.ru/nebula/server/status"
  },
  {
    name: "wl",
    connect: "https://game2.station14.ru/wl/server/status"
  },
  {
  	name: "frontier",
  	connect: "https://arles.station14.ru/frontier-main/server/status"
  },
  {
  	name: "marines",
  	connect: "https://game1.station14.ru/marines-main/server/status"
  },
  {
  	name:"stalker",
  	connect: "https://game.stalkers14.xyz/status"
  }
];

function zIndexPosition() {
    var z_index = 100;
    $(".z_index_position div").each(function(index, domEl){
        $(domEl).css({"z-index": z_index})
        z_index--;
    })
}

function kerisarTest() {
  console.log("Проверка консоли");
  const currentUrl = window.location.href;
  console.log("currentUrl", currentUrl);

  const jsTest = document.getElementById("jsTest");
  console.log("jsTest", jsTest);
  const buttonTest = document.createElement('button');
  buttonTest.classList.add('testButtonJs');
  buttonTest.textContent = "Привет, я кнопка. Пока я ничего не делаю";
  jsTest.appendChild(buttonTest);
  const kerisarPicture = document.createElement('img');
  kerisarPicture.setAttribute('src',
    "https://thumb.cloud.mail.ru/weblink/thumb/xw1/LLmd/Qui7Xbp6g");
  jsTest.appendChild(kerisarPicture);
  
  
  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) {
  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) {
    if (error) {
      console.error(error); // Обработка ошибок
    } else {
      //console.log("Ответ получен", data)
      const serverInfo = {
      	name: data.name,
        round: data.round_id,
        status: data.run_level,
        map: data.map,
        time: new Date(data.round_start_time).toLocaleString(),
        players: data.players,
        preset: data.preset
      };
      	shangeServersInfo(serverInfo, name);
      //console.log(serverInfo);
    }
  });
}


function standartServersInfoAll() {
	for (var i = 0; i < serversStatus.length; i++) {
		standartServersInfo(serversStatus[i].connect, serversStatus[i].name);
	}
}


$(document).ready(function() {
	if (currentURL.includes("Kerisar")) {
		kerisarTest();
		standartServersInfoAll();
	}
	if (document.querySelector(".z_index_position")) {
        zIndexPosition();
        
	}
});

/*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);
      });
    }
  });
}


/**
 * Taken from https://wiki.ss220.space/index.php?title=MediaWiki:Common.js&oldid=35626
 */

/* Variables for interface text used throughout the script, for ease of translating */
var i18n = {
    // Collapsible elements and page loader
    hideText: 'скрыть',
    showText: 'показать',
    
    // Page loader
    loadErrorTitle: 'Возникла ошибка при загрузке содержимого'
};

var mcw = window.mcw = {};

/* Keep track of delegated events on dynamic content */
mcw.events = {};
/* Fired whenever wiki content is added. (#mw-content-text, live preview, load page, etc.) */
mw.hook( 'wikipage.content' ).add( function( $wikipageContent ) {
/**
 * Page loader
 *
 * Allows a page to be downloaded and displayed on demand.
 * Use with Template:LoadPage and Template:LoadBox
 */

( function() {
	var $loadPage = $wikipageContent.find( '.load-page' );
	if ( !$loadPage.length ) {
		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 } );
			} );
		} );
	} );
}() );

/**
 * Element animator
 *
 * 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 );
	}
}() );

} );

// SS220 import end