注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
$(function() {
if (mw.config.get('wgPageName') == '首页') {
/* 获取服务器人数信息 */
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);
/* 获取海报 */
if ($('body.page-首页').length) {
var newDiv = $('<div>', {
'class': 'banner-image'
});
$('#content').before(newDiv);
}
/* 字体动画 */
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();
} else if (mw.config.get('wgPageName') == '首页副本') {
(function() {
/**
* 水平工具栏控制移动方向的函数
*
* @param { "left" | "right" } direction - 移动的方向,只能是 "left" 或 "right"
* @returns {void}
*/
function navHorizonTool(direction) {
const horizonTool = $(".h2-nav .h2-nav__horizonTool");
const switchLeft = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchLeft .h2-comp-buttonClick");
const switchRight = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchRight .h2-comp-buttonClick");
var horizonToolIndex = parseInt(horizonTool.css("--nav-horizonTool-show-block"));
const totalSwitches = $(".h2-nav .h2-nav__horizonTool [class^='nav-horizonTool-block']").length - 1;
if (direction == "left") {
horizonToolIndex = Math.max(0, horizonToolIndex - 1);
} else if (direction == "right") {
horizonToolIndex = Math.min(totalSwitches, horizonToolIndex + 1);
}
horizonTool.css("--nav-horizonTool-show-block", horizonToolIndex);
switchLeft.toggleClass("comp-disabled", horizonToolIndex <= 0);
switchRight.toggleClass("comp-disabled", horizonToolIndex >= totalSwitches);
}
$(function() {
/**
* 插入头图
*/
$('<div>', {
class: 'banner-image'
}).insertBefore('#content');
/**
* 水平工具栏初始化按钮
*/
const horizonToolIndex = parseInt($(".h2-nav .h2-nav__horizonTool").css("--nav-horizonTool-show-block"));
const totalSwitches = $(".h2-nav .h2-nav__horizonTool [class^='nav-horizonTool-block']").length - 1;
$(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchLeft .h2-comp-buttonClick").toggleClass("comp-disabled", horizonToolIndex <= 0);
$(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchRight .h2-comp-buttonClick").toggleClass("comp-disabled", horizonToolIndex >= totalSwitches);
$(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchLeft .h2-comp-buttonClick").on("click", function() {
navHorizonTool("left");
});
$(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchRight .h2-comp-buttonClick").on("click", function() {
navHorizonTool("right");
});
/**
* 显示服务器人数
*/
const onlineStatus = $(".h2-header > .h2-header__toolbar .h2-header__serverStatus .header-serverStatus-onlineStatus");
const onlinePlayer = $(".h2-header > .h2-header__toolbar .h2-header__serverStatus .header-serverStatus-onlinePlayer");
const onlineStatusColor = {
0: "var(--header-serverStatus-status--0)",
1: "var(--header-serverStatus-status--1)",
2: "var(--header-serverStatus-status--2)",
3: "var(--header-serverStatus-status--3)",
};
/**
* 发送请求显示服务器人数的函数
*
* @param {void}
* @returns {void}
*/
function headerServerStatusRequest() {
$.getJSON("https://api.hydcraft.cn/query/NitrogenStatus.php", function(data) {
if (data.code == 200) {
let onlinePlayerIndex;
let onlineStatusText;
if (data.status == 3) {
if (data.players.now == -1 || data.players.max == -1) {
onlinePlayerIndex = 2;
onlineStatusText = `服崩了`;
} else {
onlinePlayerIndex = 3;
onlineStatusText = `${data.players.now}/${data.players.max}`;
}
} else if (data.status == 2) {
onlinePlayerIndex = 2;
onlineStatusText = `正在开`;
} else if (data.status == 1) {
onlinePlayerIndex = 2;
onlineStatusText = `正在关`;
} else if (data.status == 0) {
onlinePlayerIndex = 1;
onlineStatusText = `服没开`;
}
onlineStatus.css("background", onlineStatusColor[onlinePlayerIndex]);
onlinePlayer.text(onlineStatusText);
} else {
onlineStatus.css("background", onlineStatusColor[0]);
onlinePlayer.text(`API 炸了`);
}
})
.fail(function(xhr) {
onlineStatus.css("background", onlineStatusColor[0]);
onlinePlayer.text(`查不到`);
});
}
headerServerStatusRequest();
setInterval(headerServerStatusRequest, 60 * 1000);
});
return {
navHorizonTool: navHorizonTool
}
})();
}
});