MediaWiki:Common.js:修订间差异

MediaWiki界面页面
无编辑摘要
小无编辑摘要
 
(未显示同一用户的5个中间版本)
第21行: 第21行:
                     var max = data.players ? data.players.max : '?';
                     var max = data.players ? data.players.max : '?';
                     el.innerHTML = '<span style="color:#17b3a8; font-weight:700;">● 服务器运行中</span>' +
                     el.innerHTML = '<span style="color:#17b3a8; font-weight:700;">● 服务器运行中</span>' +
                         ' &nbsp;·&nbsp; 在线人数:<b style="color:#111827;">' + online + '</b> / ' + max;
                         ' &nbsp;·&nbsp; 在线人数:<b style="color:var(--xh-text-strong);">' + online + '</b> / ' + max;
                 } else {
                 } else {
                     el.innerHTML = '<span style="color:#d22; font-weight:700;">● 服务器已离线</span>';
                     el.innerHTML = '<span style="color:#d22; font-weight:700;">● 服务器已离线</span>';
第31行: 第31行:
     }
     }


    /* 等首屏空闲后再请求,避免和页面渲染抢资源 */
     if ( 'requestIdleCallback' in window ) {
     if ( 'requestIdleCallback' in window ) {
         requestIdleCallback( run, { timeout: 3000 } );
         requestIdleCallback( run, { timeout: 3000 } );

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