MediaWiki:Common.js: Difference between revisions
B4ttl3m4st3r (talk | contribs) (Replaced content with "alert("JS is working!");") Tag: Replaced |
B4ttl3m4st3r (talk | contribs) No edit summary Tag: Manual revert |
||
| (3 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
function countdownToChristmas() { | |||
var now = new Date(); | |||
var targetDate = new Date(now.getFullYear(), 11, 25); // Dec 25 of current year | |||
if (now > targetDate) { | |||
targetDate.setFullYear(targetDate.getFullYear() + 1); | |||
} | |||
function updateCountdown() { | |||
var now = new Date(); | |||
var diff = targetDate - now; | |||
if (diff <= 0) { | |||
document.getElementById('xmas-timer').innerText = "Merry Christmas!"; | |||
return; | |||
} | |||
var days = Math.floor(diff / (1000 * 60 * 60 * 24)); | |||
var hours = Math.floor((diff / (1000 * 60 * 60)) % 24); | |||
var minutes = Math.floor((diff / (1000 * 60)) % 60); | |||
var seconds = Math.floor((diff / 1000) % 60); | |||
document.getElementById('xmas-timer').innerText = | |||
"Countdown to Christmas: " + days + "d " + hours + "h " + minutes + "m " + seconds + "s"; | |||
} | |||
updateCountdown(); | |||
setInterval(updateCountdown, 1000); | |||
} | |||
$(document).ready(countdownToChristmas); | |||
Latest revision as of 17:01, 28 July 2025
function countdownToChristmas() {
var now = new Date();
var targetDate = new Date(now.getFullYear(), 11, 25); // Dec 25 of current year
if (now > targetDate) {
targetDate.setFullYear(targetDate.getFullYear() + 1);
}
function updateCountdown() {
var now = new Date();
var diff = targetDate - now;
if (diff <= 0) {
document.getElementById('xmas-timer').innerText = "Merry Christmas!";
return;
}
var days = Math.floor(diff / (1000 * 60 * 60 * 24));
var hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
var minutes = Math.floor((diff / (1000 * 60)) % 60);
var seconds = Math.floor((diff / 1000) % 60);
document.getElementById('xmas-timer').innerText =
"Countdown to Christmas: " + days + "d " + hours + "h " + minutes + "m " + seconds + "s";
}
updateCountdown();
setInterval(updateCountdown, 1000);
}
$(document).ready(countdownToChristmas);