MediaWiki:Mainpage.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第1行: 第1行:
/* Player */
$(function() {
if ($("#live-player-status").length > 0) {
   /* Player */
   $.getJSON("https://mcapi.us/server/status?ip=helium.hydcraft.cn&port=25565", function(data) {
   if ($("#live-player-status").length > 0) {
   if (data.online == true) {
     $.getJSON("https://mcapi.us/server/status?ip=helium.hydcraft.cn&port=25565", function(data) {
     $("#live-info-start").css("display" , "block");
     if (data.online == true) {
     var curPlayers = data.players.now;
       $("#live-info-start").css("display" , "block");
     var maxPlayers = data.players.max;
       var curPlayers = data.players.now;
     var width = curPlayers / maxPlayers;
       var maxPlayers = data.players.max;
       var width = curPlayers / maxPlayers;


     var statusText = curPlayers + " / " + maxPlayers;
       var statusText = curPlayers + " / " + maxPlayers;
    
      
     if (curPlayers > maxPlayers)
       if (curPlayers > maxPlayers)
       $("#live-player-curmax").css("display" , "block");
         $("#live-player-curmax").css("display" , "block");
     else if (curPlayers == maxPlayers)
       else if (curPlayers == maxPlayers)
       $("#live-player-max").css("display" , "block");
         $("#live-player-max").css("display" , "block");
     else if (curPlayers < maxPlayers)
       else if (curPlayers < maxPlayers)
       $("#live-player-normal").css("display" , "block");
         $("#live-player-normal").css("display" , "block");
     else if (curPlayers == maxPlayers / 2)
       else if (curPlayers == maxPlayers / 2)
       $("#live-player-center").css("display" , "block");
         $("#live-player-center").css("display" , "block");


     if (curPlayers <= maxPlayers / 2)
       if (curPlayers <= maxPlayers / 2)
       $("#live-player-progress").css("background-color" , "#096dd9");
         $("#live-player-progress").css("background-color" , "#096dd9");
     else if(curPlayers > maxPlayers / 2 && curPlayers <= maxPlayers * 0.9)
       else if(curPlayers > maxPlayers / 2 && curPlayers <= maxPlayers * 0.9)
       $("#live-player-progress").css("background-color" , "#ff7440");
         $("#live-player-progress").css("background-color" , "#ff7440");
     else if(curPlayers > maxPlayers * 0.9)
       else if(curPlayers > maxPlayers * 0.9)
       $("#live-player-progress").css("background-color" , "#a52a2a");
         $("#live-player-progress").css("background-color" , "#a52a2a");
     else 
       else 
       $("#live-player-progress").css("background-color" , "#096dd9");
         $("#live-player-progress").css("background-color" , "#096dd9");


     $("#live-player-status").html(statusText + " (" + (width * 100).toFixed(1) + "%)");
       $("#live-player-status").html(statusText + " (" + (width * 100).toFixed(1) + "%)");
     $("#live-player-progress").width(width * 100 + '%'); 
       $("#live-player-progress").width(width * 100 + '%'); 
   } else {
     } else {
     $("#live-info-stop").css("display" , "block");
       $("#live-info-stop").css("display" , "block");
     var statusText = "服务器未启动";
       var statusText = "服务器未启动";
      $("#live-player-status").html(statusText);
       $("#live-player-status").html(statusText);
      $("#live-player-progress").width(0 + '%'); 
       $("#live-player-progress").width(0 + '%')
      }
     })
 
     .fail(function (xhr) {
     if (xhr.status == 502) {
       $("#live-player-status").html("无法获取服务器信息。");
      } else {
       $("#live-player-status").html("无法获取服务器信息,错误值:" + xhr.status + "。");
       $("#live-player-progress").width(100 + '%');
       $("#live-player-progress").css("background-color" , "#ff0000");
     }
     });
    }
    }
   })
 
    
    /* Poster */
    .fail(function (xhr) {
    var page = document.querySelector("body");
    if (xhr.status == 502) {
    if (page.classList.contains('page-首页')) {
      $("#live-player-status").html("无法获取服务器信息。");
      var mwBody = document.getElementById('content');
   } else {
     var newDiv = document.createElement('div');
      $("#live-player-status").html(" 无法获取服务器信息,错误值:" + xhr.status + " 。");
      newDiv.setAttribute('class', 'header-image');
     $("#live-player-progress").width(100 + '%');
     newDiv.innerHTML = '<div class="header-image" style="background-image: linear-gradient(to top, var(--color-surface-0), transparent 150%), url(https://h2-wiki-1254268741.cos.ap-shanghai.myqcloud.com/wiki-poster.png);background-size: cover;background-position: top;height: 36vh;margin-bottom: -28vh;"></div>';
     $("#live-player-progress").css("background-color" , "#ff0000"); 
     mwBody.parentNode.insertBefore(newDiv, mwBody);
    }
    }
   });
  }


/* Poster */
   /* Animate */
var page = document.querySelector("body");
    let textBox = $('#title');
if (page.classList.contains('page-首页')) {
    let ani_index = 0;
    var mwBody = document.getElementById('content');
    let str = 'Welcome to HydCraft Wiki! :D';
    var newDiv = document.createElement('div');
    let len = str.length;
    newDiv.setAttribute('class', 'header-image');
   newDiv.innerHTML = '<div class="header-image" style="background-image: linear-gradient(to top, var(--color-surface-0), transparent 150%), url(https://h2-wiki-1254268741.cos.ap-shanghai.myqcloud.com/wiki-poster.png);background-size: cover;background-position: top;height: 36vh;margin-bottom: -28vh;"></div>';
    mwBody.parentNode.insertBefore(newDiv, mwBody);
}


/* Animate */
   function input() {
let textBox = $('#title');
     textBox.html(str.substr(0, ani_index) + '<span class="animate">|</span>');
let ani_index = 0;
     setTimeout(function() {
let str = 'Welcome to HydCraft Wiki! :D';
       ani_index++;
let len = str.length;
       if(ani_index === len + 1) {
 
         $('.animate').addClass('on');
function input() {
         return;
   textBox.html(str.substr(0, ani_index) + '<span class="animate">|</span>');
       }
   setTimeout(function() {
       input();
     ani_index++;
     }, Math.random() * 600)
     if(ani_index === len + 1) {
   }
       $('.animate').addClass('on');
       return;
     }
     input();
   }, Math.random() * 600)
}


input();
   input();
}());

2023年3月6日 (一) 23:37的版本

$(function() {
    /* Player */
    if ($("#live-player-status").length > 0) {
        $.getJSON("https://mcapi.us/server/status?ip=helium.hydcraft.cn&port=25565", function(data) {
        if (data.online == true) {
            $("#live-info-start").css("display" , "block");
            var curPlayers = data.players.now;
            var maxPlayers = data.players.max;
            var width = curPlayers / maxPlayers;

            var statusText = curPlayers + " / " + maxPlayers;
            
            if (curPlayers > maxPlayers)
                $("#live-player-curmax").css("display" , "block");
            else if (curPlayers == maxPlayers)
                $("#live-player-max").css("display" , "block");
            else if (curPlayers < maxPlayers)
                $("#live-player-normal").css("display" , "block");
            else if (curPlayers == maxPlayers / 2)
                $("#live-player-center").css("display" , "block");

            if (curPlayers <= maxPlayers / 2)
                $("#live-player-progress").css("background-color" , "#096dd9");
            else if(curPlayers > maxPlayers / 2 && curPlayers <= maxPlayers * 0.9)
                $("#live-player-progress").css("background-color" , "#ff7440");
            else if(curPlayers > maxPlayers * 0.9)
                $("#live-player-progress").css("background-color" , "#a52a2a");
            else 
                $("#live-player-progress").css("background-color" , "#096dd9");

            $("#live-player-status").html(statusText + " (" + (width * 100).toFixed(1) + "%)");
            $("#live-player-progress").width(width * 100 + '%'); 
        } else {
            $("#live-info-stop").css("display" , "block");
            var statusText = "服务器未启动";
            $("#live-player-status").html(statusText);
            $("#live-player-progress").width(0 + '%'); 
        }
        })

        .fail(function (xhr) {
        if (xhr.status == 502) {
            $("#live-player-status").html("无法获取服务器信息。");
        } else {
            $("#live-player-status").html("无法获取服务器信息,错误值:" + xhr.status + "。");
            $("#live-player-progress").width(100 + '%'); 
            $("#live-player-progress").css("background-color" , "#ff0000"); 
        }
        });
    }

    /* Poster */
    var page = document.querySelector("body");
    if (page.classList.contains('page-首页')) {
        var mwBody = document.getElementById('content');
        var newDiv = document.createElement('div');
        newDiv.setAttribute('class', 'header-image');
        newDiv.innerHTML = '<div class="header-image" style="background-image: linear-gradient(to top, var(--color-surface-0), transparent 150%), url(https://h2-wiki-1254268741.cos.ap-shanghai.myqcloud.com/wiki-poster.png);background-size: cover;background-position: top;height: 36vh;margin-bottom: -28vh;"></div>';
        mwBody.parentNode.insertBefore(newDiv, mwBody);
    }

    /* Animate */
    let textBox = $('#title');
    let ani_index = 0;
    let str = 'Welcome to HydCraft Wiki! :D';
    let len = str.length;

    function input() {
        textBox.html(str.substr(0, ani_index) + '<span class="animate">|</span>');
        setTimeout(function() {
            ani_index++;
            if(ani_index === len + 1) {
                $('.animate').addClass('on');
                return;
            }
            input();
        }, Math.random() * 600)
    }

    input();
}());
为了让您的浏览体验更加高效、方便和个性化,遵照《中华人民共和国网络安全法》和《信息安全技术个人信息安全规范》,我们需要您允许本站使用Cookies。在某些情况下,Cookies是使网站正常运行的必要条件。