MediaWiki:Mainpage.js:修订间差异

MediaWiki系统消息页面
(创建页面,内容为“$(function() { 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 ); }); function getServerStatus(type) { const apiUrlMap = { "total": "https://mcapi.us/server/status?ip=mc.fetarute.org", "survival": "https:/…”)
 
(已保护“MediaWiki:Mainpage.js”([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期)))

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

$(function() {
	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 );
	});
	
	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);
}());