跳转到内容

MediaWiki:Common.js:修订间差异

来自天明的百科全书
Ztm0929留言 | 贡献
无编辑摘要
标签已被回退
Ztm0929留言 | 贡献
无编辑摘要
标签已被回退
第55行: 第55行:
      
      
     // 新文本
     // 新文本
     var newText = `此页面最后编辑于${rel}, ${y}年${match[2]}月${match[3]}日(${weekday}) ${match[4]}`;
     var newText = `此页面最后编辑于${rel}${y}年${match[2]}月${match[3]}日(${weekday}) ${match[4]}`;
     $lastmod.text(newText);
     $lastmod.text(newText);
   }
   }
});
});

2025年9月4日 (四) 02:49的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
// Cloudflare Web Analytics
var script = document.createElement('script');
script.defer = true;
script.src = 'https://static.cloudflareinsights.com/beacon.min.js';
script.setAttribute('data-cf-beacon', '{"token": "6180aa28fe1943b48c4059a5056f4738"}');
document.head.appendChild(script);
// End Cloudflare Web Analytics

$(function () {
    // 只在 Special:Search 页面运行
    if (mw.config.get("wgCanonicalSpecialPageName") === "Search") {
        const searchTerm = mw.util.getParamValue("search");
        const googleUrl = "https://www.google.com/search?q=" + encodeURIComponent(searchTerm);

        const $googleLink = $("<p>").html(
            `你也可以到 <a href="${googleUrl}" target="_blank" rel="noopener">Google 中搜索“${searchTerm}”</a>。`
        );

        // 优先在有搜索结果时插入
        if ($(".mw-search-results").length) {
            $googleLink.insertAfter(".mw-search-results");
        }
        // 否则在没有结果提示后插入
        else if ($(".mw-search-nonefound").length) {
            $googleLink.insertAfter(".mw-search-nonefound");
        }
    }
});

$(function() {
    $('#searchInput').attr('accesskey', '/');
});

// MediaWiki:Common.js
$(function() {
  var $lastmod = $('#footer-info-lastmod'); // 页脚里的最后修改时间
  if (!$lastmod.length) return;
  var text = $lastmod.text();
  
  // 假设原始是: "此页面最后编辑于2025-09-04 02:26:39。"
  var match = text.match(/(\d{4})-(\d{2})-(\d{2}) (\d{2}:\d{2})/);
  if (match) {
    var y = +match[1], m = +match[2]-1, d = +match[3];
    var editDate = new Date(y, m, d);
    var now = new Date();
    
    // 计算相对日期
    var diffDays = Math.floor((now - editDate) / 86400000);
    var rel = (diffDays === 0) ? '今天' : (diffDays === 1 ? '昨天' : diffDays + '天前');
    
    // 星期几
    var weekdays = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
    var weekday = weekdays[editDate.getDay()];
    
    // 新文本
    var newText = `此页面最后编辑于${rel}${y}${match[2]}${match[3]}日(${weekday}${match[4]}`;
    $lastmod.text(newText);
  }
});