MediaWiki:Mainpage.js:修订间差异

MediaWiki系统消息页面
(已保护“MediaWiki:Mainpage.js”([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期)))
无编辑摘要
第1行: 第1行:
$(function() {
$(function() {
// Calculate days TEMPORARY
const today = new Date();
const targetDate = new Date('2023-12-31');
const timeDifference = targetDate - today;
const daysRemaining = Math.ceil(timeDifference / (1000 * 60 * 60 * 24));
const countdownValue = document.querySelector('#count-down .countdown__value');
countdownValue.textContent = `${daysRemaining} 天`;
// Load earch trigger
document.getElementById( 'skin-citizen-search-trigger' ).addEventListener( 'click', function() {
document.getElementById( 'skin-citizen-search-trigger' ).addEventListener( 'click', function() {
var event = new Event( 'input', { bubbles: true, composed: true } ),
var event = new Event( 'input', { bubbles: true, composed: true } ),
第7行: 第16行:
});
});
// Get server status
function getServerStatus(type) {
function getServerStatus(type) {
const apiUrlMap = {
const apiUrlMap = {

2023年10月5日 (四) 01:37的版本

$(function() {
	// Calculate days TEMPORARY
	const today = new Date();
	const targetDate = new Date('2023-12-31');
	const timeDifference = targetDate - today;
	const daysRemaining = Math.ceil(timeDifference / (1000 * 60 * 60 * 24));
	const countdownValue = document.querySelector('#count-down .countdown__value');
	countdownValue.textContent = `${daysRemaining} 天`;
	
	// Load earch trigger
	document.getElementById( 'skin-citizen-search-trigger' ).addEventListener( 'click', function() {
		var event = new Event( 'input', { bubbles: true, composed: true } ),
		checkbox = document.getElementById( 'citizen-search__checkbox' );
		checkbox.checked = true;
		checkbox.dispatchEvent( event );
	});
	
	// Get server status
	function getServerStatus(type) {
		const apiUrlMap = {
			"total": "https://mcapi.us/server/status?ip=mc.fetarute.org",
			"survival": "https://mcapi.us/server/status?ip=survival.fetarute.org",
			"creative": "https://mcapi.us/server/status?ip=creative.fetarute.org"
		}
		
		$.get(apiUrlMap[type])
		.done(function(data) {
			const serverBlock = $("#" + type);
			
			if (data.online) {
				const { players: { now, max } } = data;
				serverBlock.find(".current-info").text(`服务器已启动`);
				serverBlock.find(".current-player").text(`${now}/${max}`);
				serverBlock.find(".progress-scroll").css("width", (now / max) * 100 + "%");
			} else {
				serverBlock.find(".current-info").text(`服务器未启动`);
				serverBlock.find(".current-player").text(`-/-`);
				serverBlock.find(".progress-scroll").css("width", "0%");
			}
		})
		.fail(function(error) {
			const serverBlock = $("#" + type);
			serverBlock.find(".current-info").text(`无法发送请求,请检查网络。`);
			serverBlock.find(".current-player").text(`-/-`);
			serverBlock.find(".progress-scroll").css("width", "0%");
		});
	}

	getServerStatus("total");
	getServerStatus("survival");
	getServerStatus("creative");
	
	setInterval(function() {
		getServerStatus("total");
		getServerStatus("survival");
		getServerStatus("creative");
	}, 60 * 1000);
}());