跳转到内容

MediaWiki:Common.js:修订间差异

来自流放之路2Wiki
Admin留言 | 贡献
无编辑摘要
Admin留言 | 贡献
无编辑摘要
第4行: 第4行:
// 维护开始时间戳(2025-04-05 03:00:00 UTC)
// 维护开始时间戳(2025-04-05 03:00:00 UTC)
// MediaWiki:Common.js (安全增强版)
// MediaWiki:Common.js (安全增强版)
'use strict';  // 启用严格模式
 
'use strict';   


const startTimestamp = 1743793200;
const startTimestamp = 1743793200;
第23行: 第24行:
}
}


// 启用模块化加载
    // 更新页面显示
if (window.addEventListener) {
    const timerElement = document.getElementById("maintenance-timer");
     window.addEventListener('load', updateMaintenanceTimer);
     if (timerElement) {
} else {
        timerElement.textContent =`距离本赛季已维护${days}天${hours}时${minutes}分${seconds}秒`;
     window.attachEvent('onload', updateMaintenanceTimer);
     }
}
}
// 首次加载更新
updateMaintenanceTimer();
// 每秒刷新
setInterval(updateMaintenanceTimer, 1000);

2025年4月13日 (日) 07:40的版本

// 引入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)
// MediaWiki:Common.js (安全增强版)

'use strict';  

const startTimestamp = 1743793200;

function updateMaintenanceTimer() {
    const safeElement = document.getElementById("maintenance-timer");
    if (!safeElement) return;

    const now = Math.floor(Date.now() / 1000);
    const duration = now - startTimestamp;

    // 使用模板字符串防止注入
    safeElement.textContent = `距离本赛季已维护${
        Math.floor(duration / 86400)}${
        Math.floor((duration % 86400) / 3600)}${
        Math.floor((duration % 3600) / 60)}${
        duration % 60}秒`;
}

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

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