MediaWiki:Mainpage.js:修订间差异

MediaWiki界面页面
无编辑摘要
无编辑摘要
第252行: 第252行:
     switchRight.toggleClass("comp-disabled", horizonToolIndex >= totalSwitches);
     switchRight.toggleClass("comp-disabled", horizonToolIndex >= totalSwitches);
     horizonIndexNow.text(horizonToolIndex);
     horizonIndexNow.text(horizonToolIndex + 1);
     horizonIndexMax.text(totalSwitches);
     horizonIndexMax.text(totalSwitches + 1);
   }
   }
第262行: 第262行:
     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^='nav-horizonTool-block']").length - 1;
     const totalSwitches = $(".h2-nav .h2-nav__horizonTool [class^='nav-horizonTool-block']").length - 1;
     const horizonIndexNow = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonTool-title .h2-nav__horizonTool-blockcount .h2-nav__horizonTool-blockcountNow");
     const horizonIndexMax = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonTool-title .h2-nav__horizonTool-blockcount .h2-nav__horizonTool-blockcountMax");
     $(".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);
第273行: 第275行:
       navHorizonTool("right");
       navHorizonTool("right");
     });
     });
     horizonIndexNow.text(horizonToolIndex + 1);
     horizonIndexMax.text(totalSwitches + 1);
   });
   });

2024年3月23日 (六) 18:21的版本

$(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') == '首页副本') {
		var mainpageModule = (function() {
		    /**
		     * 插入头图
		     */
		    $('<div>').addClass('banner-image').insertBefore('#content');
		
		    /**
		     * 请求首页信息
		     * 
		     * @param {void}
		     * @returns {void}
		     */
		    function mainpageInfoRequest() {
		        let formattedToday = new Date().toISOString().split('T')[0];
		
		        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 tendersWrapper = $(".h2-nav .h2-nav__horizonTool .nav-horizonTool-block--1 > .h2-nav__tenders .nav-tenders-content");
		        const tendersCount = $(".h2-nav .h2-nav__horizonTool .nav-horizonTool-block--1 > .h2-nav__tenders .nav-tenders-header .nav-tenders-header__count .nav-tenders-header__countvalue");
		        const statisticsPlayerTotal = $(".h2-nav .h2-nav__horizonTool .nav-horizonTool-block--1 > .h2-nav__statistics .nav-horizon-block--statistics__cardWrapper .nav-horizon-block--statistics__playerTotal .nav-horizon-block--statistics__content .nav-horizon-block--statistics__count");
		        const statisticsEntTotal = $(".h2-nav .h2-nav__horizonTool .nav-horizonTool-block--1 > .h2-nav__statistics .nav-horizon-block--statistics__cardWrapper .nav-horizon-block--statistics__entTotal .nav-horizon-block--statistics__content .nav-horizon-block--statistics__count");
		        const statisticsLauncherCurrent = $(".h2-nav .h2-nav__horizonTool .nav-horizonTool-block--1 > .h2-nav__statistics .nav-horizon-block--statistics__cardWrapper .nav-horizon-block--statistics__launcherCurrent .nav-horizon-block--statistics__content .nav-horizon-block--statistics__count");
		        
		        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)",
		        };
		
		        $.getJSON("https://api.hydcraft.cn/query/MainpageInfoQuery.php", function(data) {
		            /**
		             * 显示服务器人数
		             */
		            if (data.server_status.nitrogen.code == 200) {
		                let onlinePlayerIndex;
		                let onlineStatusText;
		
		                if (data.server_status.nitrogen.status == 3) {
		                    if (data.server_status.nitrogen.players.now == -1 || data.server_status.nitrogen.max == -1) {
		                        onlinePlayerIndex = 2;
		                        onlineStatusText = `服崩了`;
		                    } else {
		                        onlinePlayerIndex = 3;
		                        onlineStatusText = `${data.server_status.nitrogen.players.now}/${data.server_status.nitrogen.players.max}`;
		                    }
		                } else if (data.server_status.nitrogen.status == 2) {
		                    onlinePlayerIndex = 2;
		                    onlineStatusText = `正在开`;
		                } else if (data.server_status.nitrogen.status == 1) {
		                    onlinePlayerIndex = 2;
		                    onlineStatusText = `正在关`;
		                } else if (data.server_status.nitrogen.status == 0) {
		                    onlinePlayerIndex = 1;
		                    onlineStatusText = `服没开`;
		                }
		
		                onlineStatus.css("background", onlineStatusColor[onlinePlayerIndex]);
		                onlinePlayer.text(onlineStatusText);
		            } else {
		                onlineStatus.css("background", onlineStatusColor[0]);
		                onlinePlayer.text(`API 炸了`);
		            }
		
		            /**
		             * 招标信息
		             */
		            let tendersMonthlyCount = 0;
		            tendersWrapper.empty();
		            $.each(data.server_community.server_tenders, function(index, tender) {
		                if (tender.post_date.split(' ')[0] == tendersMonthlyCount)
		                    tendersMonthlyCount++;
		
		                let tendersBlockPrefixMap = {
		                    10: '招标中',
		                    11: '已中标',
		                    12: '开工中',
		                    13: '已交付'
		                };
		
		                let tendersBlockPrefixIconMap = {
		                    10: 'https://h2-wiki-1254268741.cos.ap-shanghai.myqcloud.com/e/ee/Mainpage-Exchange.svg',
		                    11: 'https://h2-wiki-1254268741.cos.ap-shanghai.myqcloud.com/3/35/Mainpage-Handshake.svg',
		                    12: 'https://h2-wiki-1254268741.cos.ap-shanghai.myqcloud.com/5/5f/Mainpage-Construct.svg',
		                    13: 'https://h2-wiki-1254268741.cos.ap-shanghai.myqcloud.com/d/d5/Mainpage-Done.svg'
		                }
		                
		                const tendersBlockTemplate = `
		                    <div class="nav-tenders-block">
		                        <div class="nav-tenders-block__top">
		                            <div class="nav-tenders-block__prefix">${tendersBlockPrefixMap[tender.prefix_id]}</div>
		                            <div class="nav-tenders-block__icon"><img src="${tendersBlockPrefixIconMap[tender.prefix_id]}"></div>
		                        </div>
		                        <div class="nav-tenders-block__bottom">
		                            <div class="nav-tenders-block__title"><a class="nav-tenders-block__link" href="${tender.view_url}">${tender.title}</a></div>
		                            <div class="nav-tenders-block__user">
		                                <div class="nav-tenders-block__time">${tender.post_date}</div>
		                                <a class="nav-tenders-block__username" href="${tender.user_view_url}"><img src="${tender.user_avatar}">${tender.username}</a>
		                            </div>
		                        </div>
		                    </div>
		                `;
		
		                tendersWrapper.append(tendersBlockTemplate);
		                tendersCount.text(tendersMonthlyCount);
		            });
		
		            /**
		             * 统计信息
		             */
		            statisticsPlayerTotal.text(data.server_count.player_total);
		            statisticsEntTotal.text(data.server_count.enterprise_total);
		            statisticsLauncherCurrent.text(data.server_count.launcher_current.nitrogen);
		        })
		
		        .fail(function(xhr) {
		            onlineStatus.css("background", onlineStatusColor[0]);
		            onlinePlayer.text(`查不到`);
		
		            tendersWrapper.empty();
		            tendersCount.text(`-`);
		
		            statisticsPlayerTotal.text(`-`);
		            statisticsEntTotal.text(`-`);
		            statisticsLauncherCurrent.text(`-`);
		        });
		    }
		
		    /**
		     * 水平工具栏控制移动方向的函数
		     * 
		     * @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");
		        const horizonIndexNow = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonTool-title .h2-nav__horizonTool-blockcount .h2-nav__horizonTool-blockcountNow");
		        const horizonIndexMax = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonTool-title .h2-nav__horizonTool-blockcount .h2-nav__horizonTool-blockcountMax");
		        
		        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);
		
		        horizonIndexNow.text(horizonToolIndex + 1);
		        horizonIndexMax.text(totalSwitches + 1);
		    }
		
		    $(function() {
		        /**
		         * 水平工具栏初始化按钮
		         */
		        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;
		        const horizonIndexNow = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonTool-title .h2-nav__horizonTool-blockcount .h2-nav__horizonTool-blockcountNow");
		        const horizonIndexMax = $(".h2-nav .h2-nav__horizonTool .h2-nav__horizonTool-title .h2-nav__horizonTool-blockcount .h2-nav__horizonTool-blockcountMax");
		
		        $(".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");
		        });
		
		        horizonIndexNow.text(horizonToolIndex + 1);
		        horizonIndexMax.text(totalSwitches + 1);
		    });
		
		    mainpageInfoRequest();
		    setInterval(mainpageInfoRequest, 60 * 1000);
		
		    return {
		        navHorizonTool: navHorizonTool
		    }
		})();
	}
});
为了让您的浏览体验更加高效、方便和个性化,遵照《中华人民共和国网络安全法》和《信息安全技术个人信息安全规范》,我们需要您允许本站使用Cookies。在某些情况下,Cookies是使网站正常运行的必要条件。