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

Материал из Space Station 14 Вики
мНет описания правки
мНет описания правки
Строка 104: Строка 104:
   //kerisarTest();
   //kerisarTest();
    
    
   //console.log(standartServersInfo("https://game2.station14.ru/main/server/status"));
   standartServersInfo(serversStatus[0].name);
    
    
});
});

Версия от 17:51, 20 июня 2024

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"
  }
];

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

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 standartServersInfo(connect) {

getServersInfo(connect, function(error, data) {
    if (error) {
      console.error(error); // Обработка ошибок
    } else {
      //console.log("Ответ получен", data)
      const serverInfo = {
        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
      };
      
      const currentURL = window.location.href;
      
      if (currentURL.includes("Kerisar")) {
      	const jsTest = document.getElementById("jsTest");
      	console.log("jsTest", jsTest);
      	const divServer = document.createElement('div');
      	divServer.textContent = JSON.stringify(serverInfo);
      	jsTest.appendChild(divServer);
      }
      
      //console.log(serverInfo);
    }
  });
}



$(document).ready(function() {
  //kerisarTest();
  
  standartServersInfo(serversStatus[0].name);
  
});

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