跳转到内容

MediaWiki:Common.js:修订间差异

来自流放之路2Wiki
Admin留言 | 贡献
无编辑摘要
Admin留言 | 贡献
无编辑摘要
 
(未显示同一用户的8个中间版本)
第1行: 第1行:
// 引入jQuery计时器插件[6](@ref)
// 引入jQuery计时器插件[6](@ref)
mw.loader.load('//cdn.jsdelivr.net/npm/jquery-countdown@2.2.0/dist/jquery.countdown.min.js');
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)
// 维护开始时间(示例:2020-09-01 00:00:00 UTC)
// 活动截止时间戳(2025-04-23 23:59:00 UTC+8)
const startTimestamp = 1743793200;
const endTimestamp = Date.parse("2025-04-23T23:59:00+08:00");
 
function updateMaintenanceTimer() {
    const now = Math.floor(Date.now() / 1000); // 当前时间戳(秒)
    const duration = now - startTimestamp;


function updateCountdown() {
    // 计算天、小时、分钟
     const now = new Date().getTime();
    const days = Math.floor(duration / 86400);
     const duration = endTimestamp - now;
     const hours = Math.floor((duration % 86400) / 3600);
    const minutes = Math.floor((duration % 3600) / 60);
     const seconds = duration % 60;


     if (duration <= 0) {
     // 更新页面显示
        document.getElementById("timer").innerText = "活动已结束";
    const timerElement = document.getElementById("maintenance-timer");
         return;
    if (timerElement) {
         timerElement.textContent =`距离本赛季已维护${days}天${hours}时${minutes}分${seconds}秒`;
     }
     }
    const days = Math.floor(duration / (1000 * 60 * 60 * 24));
    const hours = Math.floor((duration % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    const minutes = Math.floor((duration % (1000 * 60 * 60)) / (1000 * 60));
    const seconds = Math.floor((duration % (1000 * 60)) / 1000);
    document.getElementById("timer").innerText =
        `距离全角色限免结束还有${days}天${hours}时${minutes}分${seconds}秒`;
}
}


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

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