MediaWiki:Common.js: Difference between revisions

From FHX Wiki
(Created page with "function countdownToChristmas() { const targetDate = new Date(new Date().getFullYear(), 11, 25); // Dec 25 of current year const now = new Date(); // If Christmas already passed this year, use next year's Christmas if (now > targetDate) { targetDate.setFullYear(targetDate.getFullYear() + 1); } function updateCountdown() { const now = new Date(); const diff = targetDate - now; if (diff <= 0) { docu...")
 
No edit summary
Tag: Manual revert
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
function countdownToChristmas() {
function countdownToChristmas() {
     const targetDate = new Date(new Date().getFullYear(), 11, 25); // Dec 25 of current year
     var now = new Date();
    const now = new Date();
    var targetDate = new Date(now.getFullYear(), 11, 25); // Dec 25 of current year
   
 
    // If Christmas already passed this year, use next year's Christmas
     if (now > targetDate) {
     if (now > targetDate) {
         targetDate.setFullYear(targetDate.getFullYear() + 1);
         targetDate.setFullYear(targetDate.getFullYear() + 1);
Line 9: Line 8:


     function updateCountdown() {
     function updateCountdown() {
         const now = new Date();
         var now = new Date();
         const diff = targetDate - now;
         var diff = targetDate - now;


         if (diff <= 0) {
         if (diff <= 0) {
             document.getElementById('xmas-timer').innerText = "🎄 Merry Christmas!";
             document.getElementById('xmas-timer').innerText = "Merry Christmas!";
             return;
             return;
         }
         }


         const days = Math.floor(diff / (1000 * 60 * 60 * 24));
         var days = Math.floor(diff / (1000 * 60 * 60 * 24));
         const hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
         var hours = Math.floor((diff / (1000 * 60 * 60)) % 24);
         const minutes = Math.floor((diff / (1000 * 60)) % 60);
         var minutes = Math.floor((diff / (1000 * 60)) % 60);
         const seconds = Math.floor((diff / 1000) % 60);
         var seconds = Math.floor((diff / 1000) % 60);


         document.getElementById('xmas-timer').innerText =
         document.getElementById('xmas-timer').innerText =
             `🎅 Countdown to Christmas: ${days}d ${hours}h ${minutes}m ${seconds}s`;
             "Countdown to Christmas: " + days + "d " + hours + "h " + minutes + "m " + seconds + "s";
     }
     }


     updateCountdown(); // initial call
     updateCountdown();
     setInterval(updateCountdown, 1000);
     setInterval(updateCountdown, 1000);
}
}


$(document).ready(countdownToChristmas);
$(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);