跳转到内容

MediaWiki:Common.js:修订间差异

来自简中Robloxian Wiki
无编辑摘要
无编辑摘要
 
(未显示同一用户的4个中间版本)
第1行: 第1行:
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
$(function() {
$(function() {
     var PAD = 6;
     var PAD = 6;
    var BASE_URL = 'https://wiki.meltfi.top/Special:Filepath/';
     var container = document.getElementById('neko-page-counter');
     var container = document.getElementById('neko-page-counter');
      
      
     if (!container) {
     if (!container) return;
        console.log('[NekoDebug] 容器不存在');
        return;
    }
      
      
     // 检查 wgNumberOfPages
     // 用 API 获取全站页面总数
     var total = mw.config.get('wgNumberOfPages');
     var total = 0;
    console.log('[NekoDebug] wgNumberOfPages =', total);
      
      
     // 如果获取失败,先用测试数字 123456 验证图片路径
     $.ajax({
    if (!total || total === 0) {
         url: mw.util.wikiScript('api'),
         console.log('[NekoDebug] 页面总数为 0 或获取失败,临时使用测试数字 123456');
        data: {
         total = 123456;
            action: 'query',
     }
            meta: 'siteinfo',
            siprop: 'statistics',
            format: 'json'
        },
        dataType: 'json',
        async: false,
         success: function(data) {
            if (data.query && data.query.statistics && data.query.statistics.pages) {
                total = data.query.statistics.pages;
            }
        }
     });
   
    // 如果 API 也失败,fallback 到 0
    if (!total) total = 0;
      
      
     var digits = String(total).padStart(PAD, '0').split('');
     var digits = String(total).padStart(PAD, '0').split('');
    console.log('[NekoDebug] 拆解结果:', digits);
      
      
     container.innerHTML = '';
     container.innerHTML = '';
第29行: 第36行:
     var imgW = Math.max(28, Math.min(100, Math.floor((parentW - 20) / PAD)));
     var imgW = Math.max(28, Math.min(100, Math.floor((parentW - 20) / PAD)));
     var imgH = Math.round(imgW * 1.25);
     var imgH = Math.round(imgW * 1.25);
    console.log('[NekoDebug] 容器宽度:', parentW, '单张尺寸:', imgW, 'x', imgH);
      
      
     digits.forEach(function(d, i) {
    var imageUrls = {
        '0': 'https://wiki.meltfi.top/images/d/df/0.gif',
        '1': 'https://wiki.meltfi.top/images/b/b5/1.gif',
        '2': 'https://wiki.meltfi.top/images/2/27/2.gif',
        '3': 'https://wiki.meltfi.top/images/0/06/3.gif',
        '4': 'https://wiki.meltfi.top/images/8/8f/4.gif',
        '5': 'https://wiki.meltfi.top/images/6/6a/5.gif',
        '6': 'https://wiki.meltfi.top/images/b/bd/6.gif',
        '7': 'https://wiki.meltfi.top/images/e/e7/7.gif',
        '8': 'https://wiki.meltfi.top/images/4/40/8.gif',
        '9': 'https://wiki.meltfi.top/images/3/30/9.gif',
    };
   
     digits.forEach(function(d) {
         var img = document.createElement('img');
         var img = document.createElement('img');
        var url = BASE_URL + d + '.gif';
         img.src = imageUrls[d];
         img.src = url;
         img.alt = d;
         img.alt = d;
         img.style.cssText = 'width:' + imgW + 'px;height:' + imgH + 'px;object-fit:contain;image-rendering:pixelated;display:block;';
         img.style.cssText = 'width:' + imgW + 'px;height:' + imgH + 'px;object-fit:contain;image-rendering:pixelated;display:block;';
       
        console.log('[NekoDebug] 第', i, '张 URL:', url);
       
        img.onload = function() {
            console.log('[NekoDebug] 第', i, '张加载成功:', d + '.gif');
        };
          
          
         img.onerror = function() {
         img.onerror = function() {
            console.log('[NekoDebug] 第', i, '张加载失败:', d + '.gif', 'URL:', url);
             var fb = document.createElement('div');
             var fb = document.createElement('div');
             fb.textContent = d;
             fb.textContent = d;

2026年7月13日 (一) 22:21的最新版本

$(function() {
    var PAD = 6;
    var container = document.getElementById('neko-page-counter');
    
    if (!container) return;
    
    // 用 API 获取全站页面总数
    var total = 0;
    
    $.ajax({
        url: mw.util.wikiScript('api'),
        data: {
            action: 'query',
            meta: 'siteinfo',
            siprop: 'statistics',
            format: 'json'
        },
        dataType: 'json',
        async: false,
        success: function(data) {
            if (data.query && data.query.statistics && data.query.statistics.pages) {
                total = data.query.statistics.pages;
            }
        }
    });
    
    // 如果 API 也失败,fallback 到 0
    if (!total) total = 0;
    
    var digits = String(total).padStart(PAD, '0').split('');
    
    container.innerHTML = '';
    container.style.cssText = 'display:flex;align-items:flex-end;justify-content:center;gap:0;padding:10px;background:#0f0f1a;border-radius:8px;border:1px solid #2a2a40;min-height:100px;';
    
    var parentW = container.parentElement ? container.parentElement.clientWidth : 600;
    var imgW = Math.max(28, Math.min(100, Math.floor((parentW - 20) / PAD)));
    var imgH = Math.round(imgW * 1.25);
    
    var imageUrls = {
        '0': 'https://wiki.meltfi.top/images/d/df/0.gif',
        '1': 'https://wiki.meltfi.top/images/b/b5/1.gif',
        '2': 'https://wiki.meltfi.top/images/2/27/2.gif',
        '3': 'https://wiki.meltfi.top/images/0/06/3.gif',
        '4': 'https://wiki.meltfi.top/images/8/8f/4.gif',
        '5': 'https://wiki.meltfi.top/images/6/6a/5.gif',
        '6': 'https://wiki.meltfi.top/images/b/bd/6.gif',
        '7': 'https://wiki.meltfi.top/images/e/e7/7.gif',
        '8': 'https://wiki.meltfi.top/images/4/40/8.gif',
        '9': 'https://wiki.meltfi.top/images/3/30/9.gif',
    };
    
    digits.forEach(function(d) {
        var img = document.createElement('img');
        img.src = imageUrls[d];
        img.alt = d;
        img.style.cssText = 'width:' + imgW + 'px;height:' + imgH + 'px;object-fit:contain;image-rendering:pixelated;display:block;';
        
        img.onerror = function() {
            var fb = document.createElement('div');
            fb.textContent = d;
            fb.style.cssText = 'width:' + imgW + 'px;height:' + imgH + 'px;display:flex;align-items:center;justify-content:center;background:#333;color:#ff9ecd;font-size:' + Math.max(12, Math.floor(imgW * 0.4)) + 'px;font-weight:bold;font-family:monospace;border-radius:3px;';
            if (img.parentNode) img.parentNode.replaceChild(fb, img);
        };
        
        container.appendChild(img);
    });
});