MediaWiki:Common.js:修订间差异

MediaWiki界面页面
无编辑摘要
小无编辑摘要
 
(未显示同一用户的7个中间版本)
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
( function () {
$(function() {
    function run() {
        var el = document.getElementById( 'xh-server-status' );
        if ( !el ) return;


if ($("#live-delay-info").length > 0) {
        var ctrl = new AbortController();
  $.getJSON("https://seu.complexstudio.net/mirror/srcity.mc/mc/sysmap/data")
        var timer = setTimeout( function () { ctrl.abort(); }, 6000 );
  .done(function (data) {
 
    var routeNameSet = new Set();
        fetch( 'https://api.mcsrvstat.us/3/game.xhcity.top', {
    var delayedNames = [];
            signal: ctrl.signal,
    data[0].routes.forEach(function(route) {
            cache: 'no-store'
      var routeName = route.name.split("|")[0];
        } )
      routeNameSet.add(routeName);
            .then( function ( r ) {
      if (route.maxWaitTime > 2400) {
                clearTimeout( timer );
        if (delayedNames.indexOf(routeName) < 0) {
                if ( !r.ok ) throw new Error( r.status );
          delayedNames.push(routeName);
                return r.json();
        }
            } )
      }
            .then( function ( data ) {
    });
                if ( data.online ) {
    var statusText = "星海市现有 " + routeNameSet.size + " 条线路, " + Object.keys(data[0].stations).length + " 处车站。";
                    var online = data.players ? data.players.online : 0;
    if (delayedNames.length > 0) {
                    var max = data.players ? data.players.max : '?';
      statusText += "<br/><b style='color:red'>有线路发生阻塞:" + delayedNames.join("、") + "。</b>";
                    el.innerHTML = '<span style="color:#17b3a8; font-weight:700;">● 服务器运行中</span>' +
                        ' &nbsp;·&nbsp; 在线人数:<b style="color:var(--xh-text-strong);">' + online + '</b> / ' + max;
                } else {
                    el.innerHTML = '<span style="color:#d22; font-weight:700;">● 服务器已离线</span>';
                }
            } )
            .catch( function () {
                el.innerHTML = '<span style="color:#9ca3af;">● 状态暂时无法获取</span>';
            } );
     }
     }
    $("#live-delay-info").html(statusText);
 
  })
     if ( 'requestIdleCallback' in window ) {
  .fail(function (xhr, textStatus) {
        requestIdleCallback( run, { timeout: 3000 } );
     if (xhr.status == 502) {
      $("#live-delay-info").html("服务器当前未启动,或处于休眠状态。");
     } else {
     } else {
      $("#live-delay-info").html("<b style='color:red'>获取信息失败: " + xhr.status + " " + textStatus + "。</b>");
        setTimeout( run, 1500 );
     }
     }
  });
} )();
}
 
}());

2026年9月24日 (四) 00:20的最新版本

( function () {
    function run() {
        var el = document.getElementById( 'xh-server-status' );
        if ( !el ) return;

        var ctrl = new AbortController();
        var timer = setTimeout( function () { ctrl.abort(); }, 6000 );

        fetch( 'https://api.mcsrvstat.us/3/game.xhcity.top', {
            signal: ctrl.signal,
            cache: 'no-store'
        } )
            .then( function ( r ) {
                clearTimeout( timer );
                if ( !r.ok ) throw new Error( r.status );
                return r.json();
            } )
            .then( function ( data ) {
                if ( data.online ) {
                    var online = data.players ? data.players.online : 0;
                    var max = data.players ? data.players.max : '?';
                    el.innerHTML = '<span style="color:#17b3a8; font-weight:700;">● 服务器运行中</span>' +
                        ' &nbsp;·&nbsp; 在线人数:<b style="color:var(--xh-text-strong);">' + online + '</b> / ' + max;
                } else {
                    el.innerHTML = '<span style="color:#d22; font-weight:700;">● 服务器已离线</span>';
                }
            } )
            .catch( function () {
                el.innerHTML = '<span style="color:#9ca3af;">● 状态暂时无法获取</span>';
            } );
    }

    if ( 'requestIdleCallback' in window ) {
        requestIdleCallback( run, { timeout: 3000 } );
    } else {
        setTimeout( run, 1500 );
    }
} )();