MediaWiki:Common.js
外观
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5。
// 引入jQuery计时器插件[6](@ref)
mw.loader.load('//cdn.jsdelivr.net/npm/jquery-countdown@2.2.0/dist/jquery.countdown.min.js');
function startTimer(duration, display) {
var timer = duration, days, hours, minutes, seconds;
setInterval(function() {
days = Math.floor(timer / (60 * 60 * 24));
hours = Math.floor((timer % (60 * 60 * 24)) / (60 * 60));
minutes = Math.floor((timer % (60 * 60)) / 60);
seconds = Math.floor(timer % 60);
display.textContent = days + "天 " + hours + ":" + minutes + ":" + seconds;
if (--timer < 0) timer = duration;
}, 1000);
}
// 初始化30天倒计时
window.onload = function() {
var thirtyDays = 30 * 24 * 60 * 60,
display = document.querySelector('#timer');
startTimer(thirtyDays, display);
};