MediaWiki:Common.js:修订间差异
外观
无编辑摘要 |
无编辑摘要 |
||
第3行: | 第3行: | ||
// 维护开始时间戳(2025-04-05 03:00:00 UTC) | // 维护开始时间戳(2025-04-05 03:00:00 UTC) | ||
// MediaWiki:Common.js (安全增强版) | |||
'use strict'; // 启用严格模式 | |||
const startTimestamp = 1743793200; | const startTimestamp = 1743793200; | ||
function updateMaintenanceTimer() { | function updateMaintenanceTimer() { | ||
const now = Math.floor(Date.now() / 1000); | const safeElement = document.getElementById("maintenance-timer"); | ||
if (!safeElement) return; | |||
const now = Math.floor(Date.now() / 1000); | |||
const duration = now - startTimestamp; | const duration = now - startTimestamp; | ||
// | // 使用模板字符串防止注入 | ||
safeElement.textContent = `距离本赛季已维护${ | |||
Math.floor(duration / 86400)}天${ | |||
Math.floor((duration % 86400) / 3600)}时${ | |||
Math.floor((duration % 3600) / 60)}分${ | |||
duration % 60}秒`; | |||
} | |||
// 启用模块化加载 | |||
if (window.addEventListener) { | |||
window.addEventListener('load', updateMaintenanceTimer); | |||
} else { | |||
window.attachEvent('onload', updateMaintenanceTimer); | |||
} | } | ||
2025年4月13日 (日) 07:29的版本
// 引入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}秒`;
}
// 启用模块化加载
if (window.addEventListener) {
window.addEventListener('load', updateMaintenanceTimer);
} else {
window.attachEvent('onload', updateMaintenanceTimer);
}