Aurora Lemon(讨论 | 贡献) (撤销Aurora Lemon(讨论)的版本6871) 标签:撤销 |
Aurora Lemon(讨论 | 贡献) 小无编辑摘要 |
||
第3行: | 第3行: | ||
if ($("#live-player-status").length > 0) { | if ($("#live-player-status").length > 0) { | ||
$.getJSON("https://mcapi.us/server/status?ip=helium.hydcraft.cn&port=25565") | |||
.done(function (data) { | |||
var curPlayers = data.players.now; | |||
var maxPlayers = data.players.max; | |||
var width = curPlayers / maxPlayers; | |||
var statusText = "服务器在线人数 " + curPlayers + " / " + maxPlayers; | |||
$("#live-player-status").html(statusText); | |||
$("#live-player-progress").css("background-color" , "#096dd9"); | |||
$("#live-player-progress").width(width * 100 + '%'); | |||
}) | |||
.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"); | |||
} | } | ||
}); | |||
} | } | ||
}()); | }()); |
2023年1月8日 (日) 01:12的版本
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
$(function() {
if ($("#live-player-status").length > 0) {
$.getJSON("https://mcapi.us/server/status?ip=helium.hydcraft.cn&port=25565")
.done(function (data) {
var curPlayers = data.players.now;
var maxPlayers = data.players.max;
var width = curPlayers / maxPlayers;
var statusText = "服务器在线人数 " + curPlayers + " / " + maxPlayers;
$("#live-player-status").html(statusText);
$("#live-player-progress").css("background-color" , "#096dd9");
$("#live-player-progress").width(width * 100 + '%');
})
.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");
}
});
}
}());