Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
Content deleted Content added
imported>76561198018895007
No edit summary
imported>76561198018895007
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
const countDownDate = 'January 21 2021 05:00:00 GMT+0000';
const countDownDate = 'January 21 2021 05:00:00 GMT+0000';


Line 9: Line 8:
const days = Math.floor(total / (1000 * 60 * 60 * 24));
const days = Math.floor(total / (1000 * 60 * 60 * 24));
return {
return {
total: total,
total,
days: days,
days,
hours: hours,
hours,
minutes: minutes,
minutes,
seconds: seconds
seconds
};
};
}
}
Line 19: Line 18:
function initializeClock(id, endtime) {
function initializeClock(id, endtime) {
const clock = document.getElementById(id);
const clock = document.getElementById(id);
const timeinterval = setInterval(() => {
const timeinterval = setInterval(function() {
const t = getTimeRemaining(endtime);
const t = getTimeRemaining(endtime);
clock.innerHTML = t.days + "d " + t.hours + "h " + t.minutes + "m " + t.seconds + "s ";
clock.innerHTML = t.days + "d " + t.hours + "h " + t.minutes + "m " + t.seconds + "s ";

Revision as of 19:55, 8 January 2021

        const countDownDate = 'January 21 2021 05:00:00 GMT+0000';

        function getTimeRemaining(endtime) {
            const total = Date.parse(endtime) - Date.parse(new Date());
            const seconds = Math.floor((total / 1000) % 60);
            const minutes = Math.floor((total / 1000 / 60) % 60);
            const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
            const days = Math.floor(total / (1000 * 60 * 60 * 24));
            return {
                total,
                days,
                hours,
                minutes,
                seconds
            };
        }

        function initializeClock(id, endtime) {
            const clock = document.getElementById(id);
            const timeinterval = setInterval(function() {
                const t = getTimeRemaining(endtime);
                clock.innerHTML = t.days + "d " + t.hours + "h " + t.minutes + "m " + t.seconds + "s ";
                if (t.total <= 0) {
                    clearInterval(timeinterval);
                }
            }, 1000);
        }

        initializeClock('launch_timer', countDownDate);
🍪 We use cookies to keep session information to provide you a better experience.