Aurora Lemon(讨论 | 贡献) 小无编辑摘要 |
Aurora Lemon(讨论 | 贡献) 小无编辑摘要 |
||
第1行: | 第1行: | ||
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */ | /* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */ | ||
$(function() { | $(function() { | ||
if ($("#live-player-status").length > 0) { | if ($("#live-player-status").length > 0) { | ||
$.getJSON("https://mcapi.us/server/status?ip=helium.hydcraft.cn&port=25565") | $.getJSON("https://mcapi.us/server/status?ip=helium.hydcraft.cn&port=25565") | ||
.done(function (data) { | .done(function (data) { | ||
var curPlayers = data.players.now; | if (data.online == true) { | ||
// $("#live-info-start").css("visibility" , "visible"); | |||
$("#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" , "#ff4500"); | |||
} 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 + "%)"); | |||
$("#live-player-progress").width(width * 100 + '%'); | |||
} else { | |||
$("#live-info-stop").css("display" , "block"); | |||
var statusText = "服务器未启动"; | |||
$("#live-player-status").html(statusText); | |||
} | |||
}) | }) | ||
.fail(function (xhr) { | .fail(function (xhr) { | ||
if (xhr.status == 502) { | if (xhr.status == 502) { | ||
$("#live-player-status").html(" | $("#live-player-status").html(" 无法获取信息 。"); | ||
} else { | } else { | ||
$("#live-player-status").html("无法获取信息,错误值:" + xhr.status + "。"); | $("#live-player-status").html("无法获取信息,错误值:" + xhr.status + "。"); | ||
第27行: | 第61行: | ||
} | } | ||
}()); | }()); |
2023年1月8日 (日) 15:05的版本
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
$(function() {
if ($("#live-player-status").length > 0) {
$.getJSON("https://mcapi.us/server/status?ip=helium.hydcraft.cn&port=25565")
.done(function (data) {
if (data.online == true) {
// $("#live-info-start").css("visibility" , "visible");
$("#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" , "#ff4500");
} 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 + "%)");
$("#live-player-progress").width(width * 100 + '%');
} else {
$("#live-info-stop").css("display" , "block");
var statusText = "服务器未启动";
$("#live-player-status").html(statusText);
}
})
.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");
}
});
}
}());