Aurora Lemon(讨论 | 贡献) (哥们打错字了) |
Aurora Lemon(讨论 | 贡献) (算了哥们改回来了) |
||
第1行: | 第1行: | ||
$(function() { | |||
/* 获取服务器人数信息 */ | |||
function getServerStatus() { | |||
if ($("#live-player-status").length > 0) { | |||
$("#live-info-start").css("display" , "none"); | |||
$("#live-info-stop").css("display" , "none"); | |||
$.getJSON("https://api.hydcraft.cn/query/NitrogenStatus.php", function(data) { | |||
if (data.code == 200) { | |||
if (data.status == 3) { | |||
$("#live-info-start").css("display" , "block"); | |||
var curPlayers = data.players.now; | |||
var maxPlayers = data.players.max; | |||
var width = curPlayers / maxPlayers; | |||
var statusText = curPlayers + " / " + maxPlayers; | |||
$("#live-player-progress").css("background-color" , "#096dd9"); | |||
$("#live-player-status").html(statusText + " (" + (width * 100).toFixed(1) + "%)"); | |||
$("#live-player-progress").width(width * 100 + '%'); | |||
} else if (data.status == 2) { | |||
$("#live-info-stop").css("display" , "block"); | |||
var statusText = "服务器启动中"; | |||
$("#live-player-status").html(statusText); | |||
$("#live-player-progress").width(0 + '%'); | |||
} else if (data.status == 1) { | |||
$("#live-info-stop").css("display" , "block"); | |||
var statusText = "服务器关闭中"; | |||
$("#live-player-status").html(statusText); | |||
$("#live-player-progress").width(0 + '%'); | |||
} else if (data.status == 0) { | |||
$("#live-info-stop").css("display" , "block"); | |||
var statusText = "服务器未启动"; | |||
$("#live-player-status").html(statusText); | |||
$("#live-player-progress").width(0 + '%'); | |||
} | |||
} else { | |||
$("#live-info-stop").css("display" , "block"); | |||
var statusText = "API 无法连接服务器"; | |||
$("#live-player-status").html(statusText); | |||
$("#live-player-progress").width(0 + '%'); | |||
} | |||
}) | |||
.fail(function (xhr) { | |||
$("#live-player-status").html("无法获取服务器信息"); | |||
$("#live-player-progress").width(100 + '%'); | |||
$("#live-player-progress").css("background-color" , "#ff0000"); | |||
}); | |||
} | |||
} | |||
getServerStatus(); | |||
setInterval(getServerStatus, 60000); | |||
var interval = setInterval(function() { | |||
if (typeof sakanaLoaded !== 'undefined' && sakanaLoaded) { | |||
clearInterval(interval); | |||
animate(); | |||
} | |||
}, 100); | |||
/* 获取海报 */ | |||
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); | |||
} | |||
/* Sakana */ | |||
addCssFile("https://api.hydcraft.cn/h2wiki/assets/sakana.min.css"); | |||
importScript( 'MediaWiki:Sakana.js' ); | |||
/* 字体动画 */ | |||
function animate() { | |||
return new Promise(resolve => { | |||
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'); | |||
resolve(); // 动画执行完成后,调用 resolve() 以解析 Promise | |||
return; | |||
} | |||
input(); | |||
}, Math.random() * 600); | |||
} | |||
input(); | |||
}); | |||
} | |||
animate(); | |||
}()); |
2023年9月1日 (五) 23:38的版本
$(function() {
/* 获取服务器人数信息 */
function getServerStatus() {
if ($("#live-player-status").length > 0) {
$("#live-info-start").css("display" , "none");
$("#live-info-stop").css("display" , "none");
$.getJSON("https://api.hydcraft.cn/query/NitrogenStatus.php", function(data) {
if (data.code == 200) {
if (data.status == 3) {
$("#live-info-start").css("display" , "block");
var curPlayers = data.players.now;
var maxPlayers = data.players.max;
var width = curPlayers / maxPlayers;
var statusText = curPlayers + " / " + maxPlayers;
$("#live-player-progress").css("background-color" , "#096dd9");
$("#live-player-status").html(statusText + " (" + (width * 100).toFixed(1) + "%)");
$("#live-player-progress").width(width * 100 + '%');
} else if (data.status == 2) {
$("#live-info-stop").css("display" , "block");
var statusText = "服务器启动中";
$("#live-player-status").html(statusText);
$("#live-player-progress").width(0 + '%');
} else if (data.status == 1) {
$("#live-info-stop").css("display" , "block");
var statusText = "服务器关闭中";
$("#live-player-status").html(statusText);
$("#live-player-progress").width(0 + '%');
} else if (data.status == 0) {
$("#live-info-stop").css("display" , "block");
var statusText = "服务器未启动";
$("#live-player-status").html(statusText);
$("#live-player-progress").width(0 + '%');
}
} else {
$("#live-info-stop").css("display" , "block");
var statusText = "API 无法连接服务器";
$("#live-player-status").html(statusText);
$("#live-player-progress").width(0 + '%');
}
})
.fail(function (xhr) {
$("#live-player-status").html("无法获取服务器信息");
$("#live-player-progress").width(100 + '%');
$("#live-player-progress").css("background-color" , "#ff0000");
});
}
}
getServerStatus();
setInterval(getServerStatus, 60000);
var interval = setInterval(function() {
if (typeof sakanaLoaded !== 'undefined' && sakanaLoaded) {
clearInterval(interval);
animate();
}
}, 100);
/* 获取海报 */
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);
}
/* Sakana */
addCssFile("https://api.hydcraft.cn/h2wiki/assets/sakana.min.css");
importScript( 'MediaWiki:Sakana.js' );
/* 字体动画 */
function animate() {
return new Promise(resolve => {
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');
resolve(); // 动画执行完成后,调用 resolve() 以解析 Promise
return;
}
input();
}, Math.random() * 600);
}
input();
});
}
animate();
}());