MediaWiki:Common.js

MediaWiki interface page

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/*
     const countDownDate = 'January 21 2021 07: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: total, 
          days: days, 
          hours: hours,  
          minutes: minutes, 
          seconds: seconds
        };
    }
    function tick(id, endtime) {
      const clock = document.getElementById(id);
      if(clock != null)
      {
    	const t = getTimeRemaining(endtime);
    	clock.innerHTML = t.days + "d " + t.hours + "h " + t.minutes + "m " + t.seconds + "s ";
        if (t.total <= 0) { clearInterval(timeinterval); }
      }
    }

    function initializeClock(id, endtime) {
        const timeinterval = setInterval(function() { tick(id, endtime) }, 1000);
        tick(id, endtime);
    }

    initializeClock('launch_timer', countDownDate);
*/

function setupPagination() {
  document.querySelectorAll('.mw-parser-output .upgrade_panel').forEach(function(infobox) {
  	Array.from(infobox.getElementsByClassName('upgrade_page_button')).forEach(function(button) {
      button.parentElement.onclick = function(e) {
        e.preventDefault();
        var level = button.dataset.level;
        Array.from(infobox.getElementsByClassName('upgrade_page')).forEach(function(page) { page.classList.toggle('hidden', page.dataset.page != level) });
        Array.from(infobox.getElementsByClassName('upgrade_page_button')).forEach(function(btn) { btn.classList.toggle('active', btn === button) });
        infobox.getElementsByClassName('upgrade_put_level')[0].textContent = button.getElementsByClassName('upgrade_get_level')[0].textContent;
      };
    });
    
    var pages = Array.from(infobox.getElementsByClassName('upgrade_page'));
    var heights = [], widths = [];
    pages.forEach(function(page, index) {
      page.classList.toggle('hidden', false);
      heights.push(page.offsetHeight);
      widths.push(page.offsetWidth);
      if (index > 0) page.classList.toggle('hidden', true);
    });
    var minHeight = Math.max.apply(null, heights), minWidth = Math.max.apply(null, widths);
    pages.forEach(function(page) {
      $(page).css({'min-height': minHeight, 'min-width': minWidth});
    });
  });
}

function setupSpoilers() {
	document.querySelectorAll('.mw-parser-output .spoiler').forEach(function(spoiler) {
		spoiler.onclick = function(e) {
			if (spoiler.classList.contains('spoiler-hidden')) {
				e.preventDefault();
				spoiler.classList.remove('spoiler-hidden');
				spoiler.title = '';
			}
		};
	});
}

setupPagination();
setupSpoilers();
🍪 We use cookies to keep session information to provide you a better experience.