MediaWiki:Mainpage.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第97行: 第97行:
   animate();
   animate();
} else if (mw.config.get('wgPageName') == '首页副本') {
} else if (mw.config.get('wgPageName') == '首页副本') {
/**
(function() {
* 水平工具栏控制移动方向的函数
   /**
   * 水平工具栏控制移动方向的函数
* @param { "left" | "right" } direction - 移动的方向,只能是 "left" 或 "right"
  
* @returns {void}
   * @param { "left" | "right" } direction - 移动的方向,只能是 "left" 或 "right"
*/
   * @returns {void}
function navHorizonTool(direction) {
   */
   const horizonTool = $(".h2-nav .h2-nav__horizonTool");
   function navHorizonTool(direction) {
   const switchLeft = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchLeft .h2-comp-buttonClick");
     const horizonTool = $(".h2-nav .h2-nav__horizonTool");
   const switchRight = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchRight .h2-comp-buttonClick");
     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;
     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") {
     if (direction == "left") {
     horizonToolIndex = Math.max(0, horizonToolIndex - 1);
       horizonToolIndex = Math.max(0, horizonToolIndex - 1);
   } else if (direction == "right") {
     } else if (direction == "right") {
     horizonToolIndex = Math.min(totalSwitches, horizonToolIndex + 1);
       horizonToolIndex = Math.min(totalSwitches, horizonToolIndex + 1);
   }
     }
   horizonTool.css("--nav-horizonTool-show-block", horizonToolIndex);
     horizonTool.css("--nav-horizonTool-show-block", horizonToolIndex);
   switchLeft.toggleClass("comp-disabled", horizonToolIndex <= 0);
     switchLeft.toggleClass("comp-disabled", horizonToolIndex <= 0);
   switchRight.toggleClass("comp-disabled", horizonToolIndex >= totalSwitches);
     switchRight.toggleClass("comp-disabled", horizonToolIndex >= totalSwitches);
}
   }
$(function() {
   $(function() {
   /**
     /**
   * 插入头图
     * 插入头图
   */
     */
   $('<div>', {
     $('<div>', {
     class: 'banner-image'
       class: 'banner-image'
   }).insertBefore('#content');
     }).insertBefore('#content');
   /**
     /**
   * 水平工具栏初始化按钮
     * 水平工具栏初始化按钮
   */
     */
   const horizonToolIndex = parseInt($(".h2-nav .h2-nav__horizonTool").css("--nav-horizonTool-show-block"));
     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;
     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__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__horizonToolSwitchRight .h2-comp-buttonClick").toggleClass("comp-disabled", horizonToolIndex >= totalSwitches);
  
    
   $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchLeft .h2-comp-buttonClick").on("click", function() {
     $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchLeft .h2-comp-buttonClick").on("click", function() {
     navHorizonTool("left");
       navHorizonTool("left");
   });
     });
   $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonToolSwitchRight .h2-comp-buttonClick").on("click", function() {
     navHorizonTool("right");
   });
     $(".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)",
     const onlineStatus = $(".h2-header > .h2-header__toolbar .h2-header__serverStatus .header-serverStatus-onlineStatus");
     3: "var(--header-serverStatus-status--3)",
     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;
   * @param {void}
               onlineStatusText = `服崩了`;
   * @returns {void}
             } else {
   */
               onlinePlayerIndex = 3;
   function headerServerStatusRequest() {
               onlineStatusText = `${data.players.now}/${data.players.max}`;
     $.getJSON("https://api.hydcraft.cn/query/NitrogenStatus.php", function(data) {
             }
       if (data.code == 200) {
           } else if (data.status == 2) {
         let onlinePlayerIndex;
             onlinePlayerIndex = 2;
         let onlineStatusText;
             onlineStatusText = `正在开`;
           } else if (data.status == 1) {
         if (data.status == 3) {
           if (data.players.now == -1 || data.players.max == -1) {
             onlinePlayerIndex = 2;
             onlinePlayerIndex = 2;
             onlineStatusText = ` 服崩了`;
             onlineStatusText = ` 正在关`;
           } else {
           } else if (data.status == 0) {
             onlinePlayerIndex = 3;
             onlinePlayerIndex = 1;
             onlineStatusText = `${data.players.now}/${data.players.max}`;
             onlineStatusText = ` 服没开`;
           }
           }
         } else if (data.status == 2) {
           onlinePlayerIndex = 2;
           onlineStatus.css("background", onlineStatusColor[onlinePlayerIndex]);
           onlineStatusText = `正在开`;
           onlinePlayer.text(onlineStatusText);
         } else if (data.status == 1) {
         } else {
           onlinePlayerIndex = 2;
           onlineStatus.css("background", onlineStatusColor[0]);
           onlineStatusText = `正在关`;
           onlinePlayer.text(`API 炸了`);
         } else if (data.status == 0) {
           onlinePlayerIndex = 1;
           onlineStatusText = ` 服没开`;
         }
         }
       })
         onlineStatus.css("background", onlineStatusColor[onlinePlayerIndex]);
       .fail(function(xhr) {
         onlinePlayer.text(onlineStatusText);
       } else {
         onlineStatus.css("background", onlineStatusColor[0]);
         onlineStatus.css("background", onlineStatusColor[0]);
         onlinePlayer.text(`API 炸了`);
         onlinePlayer.text(` 查不到`);
       }
       });
     })
     }
     .fail(function (xhr) {
     headerServerStatusRequest();
       onlineStatus.css("background", onlineStatusColor[0]);
     setInterval(headerServerStatusRequest, 60 * 1000);
       onlinePlayer.text(`查不到`);
   });
     });
   return {
     navHorizonTool: navHorizonTool
   }
   }
})();
   headerServerStatusRequest()
   setInterval(headerServerStatusRequest, 60 * 1000);
})
}
}
});
});

2024年3月18日 (一) 22:17的版本

$(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
		    }
		})();
	}
});
为了让您的浏览体验更加高效、方便和个性化,遵照《中华人民共和国网络安全法》和《信息安全技术个人信息安全规范》,我们需要您允许本站使用Cookies。在某些情况下,Cookies是使网站正常运行的必要条件。