MediaWiki:Mainpage.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第1行: 第1行:
$(function() {
$(function() {
   /* 获取服务器人数信息 */
if (mw.config.get('wgPageName') == '首页') {
   function getServerStatus() {
   /* 获取服务器人数信息 */
     if ($("#live-player-status").length > 0) {
   function getServerStatus() {
$("#live-info-start").css("display" , "none");
     if ($("#live-player-status").length > 0) {
$("#live-info-stop").css("display" , "none");
$("#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) {
       $.getJSON("https://api.hydcraft.cn/query/NitrogenStatus.php", function(data) {
         if (data.status == 3) {
       if (data.code == 200) {
           $("#live-info-start").css("display" , "block");
         if (data.status == 3) {
           var curPlayers = data.players.now;
           $("#live-info-start").css("display" , "block");
           var maxPlayers = data.players.max;
           var curPlayers = data.players.now;
           var width = curPlayers / maxPlayers;
           var maxPlayers = data.players.max;
 
           var width = curPlayers / maxPlayers;
           var statusText = curPlayers + " / " + maxPlayers;
 
           var statusText = curPlayers + " / " + maxPlayers;
           $("#live-player-progress").css("background-color" , "#096dd9");
 
           $("#live-player-progress").css("background-color" , "#096dd9");
           $("#live-player-status").html(statusText + " (" + (width * 100).toFixed(1) + "%)");
           $("#live-player-progress").width(width * 100 + '%'); 
           $("#live-player-status").html(statusText + " (" + (width * 100).toFixed(1) + "%)");
         } else if (data.status == 2) {
           $("#live-player-progress").width(width * 100 + '%'); 
           $("#live-info-stop").css("display" , "block");
         } else if (data.status == 2) {
           var statusText = "服务器启动中";
           $("#live-info-stop").css("display" , "block");
           $("#live-player-status").html(statusText);
           var statusText = "服务器启动中";
           $("#live-player-progress").width(0 + '%'); 
           $("#live-player-status").html(statusText);
         } else if (data.status == 1) {
           $("#live-player-progress").width(0 + '%'); 
           $("#live-info-stop").css("display" , "block");
         } else if (data.status == 1) {
           var statusText = "服务器关闭中";
           $("#live-info-stop").css("display" , "block");
           $("#live-player-status").html(statusText);
           var statusText = "服务器关闭中";
           $("#live-player-progress").width(0 + '%'); 
           $("#live-player-status").html(statusText);
         } else if (data.status == 0) {
           $("#live-player-progress").width(0 + '%'); 
           $("#live-info-stop").css("display" , "block");
         } else if (data.status == 0) {
           var statusText = "服务器未启动";
           $("#live-info-stop").css("display" , "block");
           $("#live-player-status").html(statusText);
           var statusText = "服务器未启动";
           $("#live-player-progress").width(0 + '%'); 
           $("#live-player-status").html(statusText);
         }
           $("#live-player-progress").width(0 + '%'); 
       } else {
         }
         $("#live-info-stop").css("display" , "block");
       } else {
         var statusText = "API 无法连接服务器";
         $("#live-info-stop").css("display" , "block");
         $("#live-player-status").html(statusText);
         var statusText = "API 无法连接服务器";
         $("#live-player-progress").width(0 + '%'); 
         $("#live-player-status").html(statusText);
       }
         $("#live-player-progress").width(0 + '%'); 
       })
       }
 
       })
       .fail(function (xhr) {
         $("#live-player-status").html("无法获取服务器信息");
       .fail(function (xhr) {
         $("#live-player-progress").width(100 + '%'); 
         $("#live-player-status").html("无法获取服务器信息");
         $("#live-player-progress").css("background-color" , "#ff0000"); 
         $("#live-player-progress").width(100 + '%'); 
       });
         $("#live-player-progress").css("background-color" , "#ff0000"); 
     }
       });
   }
     }
 
   }
   getServerStatus();
   setInterval(getServerStatus, 60000);
   getServerStatus();
 
   setInterval(getServerStatus, 60000);
   var interval = setInterval(function() {
     if (typeof sakanaLoaded !== 'undefined' && sakanaLoaded) {
   var interval = setInterval(function() {
       clearInterval(interval);
     if (typeof sakanaLoaded !== 'undefined' && sakanaLoaded) {
       animate();
       clearInterval(interval);
     }
       animate();
   }, 100);
     }
 
   }, 100);
   /* 获取海报 */
if ($('body.page-首页').length) {
   /* 获取海报 */
var newDiv = $('<div>', {
if ($('body.page-首页').length) {
'class': 'banner-image',
var newDiv = $('<div>', {
'html': '<div class="banner-image></div>'
'class': 'banner-image',
});
'html': '<div class="banner-image></div>'
$('#content').before(newDiv);
});
$('#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') == '首页副本') {
/**
* 水平工具栏控制移动方向的函数
*
* @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^='h2-nav__horizonToolSwitch']").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',
     html: '<div class="banner-image"></div>'
   }).insertBefore('#content');
   /**
   * 水平工具栏初始化按钮
   */
   const horizonToolIndex = parseInt($(".h2-nav .h2-nav__horizonTool").css("--nav-horizonTool-show-block"));
   const totalSwitches = $(".h2-nav .h2-nav__horizonTool [class^='h2-nav__horizonToolSwitch']").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);
})
}
}
 
});
   /* 字体动画 */
   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();
}());

2024年3月10日 (日) 17:34的版本

$(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',
				'html': '<div class="banner-image></div>'
			});
			$('#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') == '首页副本') {
		/**
		 * 水平工具栏控制移动方向的函数
		 * 
		 * @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^='h2-nav__horizonToolSwitch']").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',
		        html: '<div class="banner-image"></div>'
		    }).insertBefore('#content');
		
		
		
		    /**
		     * 水平工具栏初始化按钮
		     */
		    const horizonToolIndex = parseInt($(".h2-nav .h2-nav__horizonTool").css("--nav-horizonTool-show-block"));
		    const totalSwitches = $(".h2-nav .h2-nav__horizonTool [class^='h2-nav__horizonToolSwitch']").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);
		})
	}
});
为了让您的浏览体验更加高效、方便和个性化,遵照《中华人民共和国网络安全法》和《信息安全技术个人信息安全规范》,我们需要您允许本站使用Cookies。在某些情况下,Cookies是使网站正常运行的必要条件。