跳转到内容

MediaWiki:Common.js:修订间差异

来自流放之路2Wiki
Admin留言 | 贡献
无编辑摘要
Admin留言 | 贡献
无编辑摘要
 
(未显示同一用户的1个中间版本)
第3行: 第3行:


// 维护开始时间戳(2025-04-05 03:00:00 UTC)
// 维护开始时间戳(2025-04-05 03:00:00 UTC)
// MediaWiki:Common.js (安全增强版)
// 维护开始时间(示例:2020-09-01 00:00:00 UTC)
'use strict';  // 启用严格模式
 
const startTimestamp = 1743793200;
const startTimestamp = 1743793200;


function updateMaintenanceTimer() {
function updateMaintenanceTimer() {
     const safeElement = document.getElementById("maintenance-timer");
     const now = Math.floor(Date.now() / 1000); // 当前时间戳(秒)
     if (!safeElement) return;
     const duration = now - startTimestamp;


     const now = Math.floor(Date.now() / 1000);
    // 计算天、小时、分钟
     const duration = now - startTimestamp;
     const days = Math.floor(duration / 86400);
    const hours = Math.floor((duration % 86400) / 3600);
     const minutes = Math.floor((duration % 3600) / 60);
    const seconds = duration % 60;


     // 使用模板字符串防止注入
     // 更新页面显示
     safeElement.textContent = `距离本赛季已维护${
     const timerElement = document.getElementById("maintenance-timer");
        Math.floor(duration / 86400)}天${
    if (timerElement) {
        Math.floor((duration % 86400) / 3600)}时${
        timerElement.textContent =`距离本赛季已维护${days}天${hours}时${minutes}分${seconds}秒`;
        Math.floor((duration % 3600) / 60)}分${
    }
        duration % 60}秒`;
}
}


// 启用模块化加载
// 首次加载更新
if (window.addEventListener) {
updateMaintenanceTimer();
    window.addEventListener('load', updateMaintenanceTimer);
// 每秒刷新
} else {
setInterval(updateMaintenanceTimer, 1000);
    window.attachEvent('onload', updateMaintenanceTimer);
}

2025年4月13日 (日) 07:45的最新版本

// 引入jQuery计时器插件[6](@ref)
mw.loader.load('//cdn.jsdelivr.net/npm/jquery-countdown@2.2.0/dist/jquery.countdown.min.js');

// 维护开始时间戳(2025-04-05 03:00:00 UTC)
// 维护开始时间(示例:2020-09-01 00:00:00 UTC)
const startTimestamp = 1743793200;

function updateMaintenanceTimer() {
    const now = Math.floor(Date.now() / 1000); // 当前时间戳(秒)
    const duration = now - startTimestamp;

    // 计算天、小时、分钟
    const days = Math.floor(duration / 86400);
    const hours = Math.floor((duration % 86400) / 3600);
    const minutes = Math.floor((duration % 3600) / 60);
    const seconds = duration % 60;

    // 更新页面显示
    const timerElement = document.getElementById("maintenance-timer");
    if (timerElement) {
        timerElement.textContent =`距离本赛季已维护${days}${hours}${minutes}${seconds}秒`;
    }
}

// 首次加载更新
updateMaintenanceTimer();
// 每秒刷新
setInterval(updateMaintenanceTimer, 1000);