Common.js

Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
$(function() {
	$(".build-template-button").click(function(){
		var $this = $(this);
		navigator.clipboard.writeText($this.prev().text());
		$this.text('Copied');
		setTimeout(function() { 
			$this.text('Copy Template Code');
		}, 2000);
	});
});

var coll = document.getElementsByClassName("collapseMB");
var i;
for (i = 0; i < coll.length; i++) {
	coll[i].addEventListener("click", function() {
		this.classList.toggle("active");
		var content = this.nextElementSibling;
		if (content.style.display === "block") {
			content.style.display = "none";
		} else {
			content.style.display = "block";
		}
	});
}

if (mw.config.get('wgIsArticle')) {
	autoConvertUTC();
}

function autoConvertUTC () {
	function pad (s) {  return (s < 10 ? '0' : '') + s; }
	var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
	$('.utc-auto-convert').each(function(i,v){
		// Get UTC time using MediaWiki {{#time: U}} epoch format
		var utcseconds = v.getAttribute('data-time');
		if (utcseconds == 'error') {
			return;
		}
		var d = new Date(0);
		d.setUTCSeconds(utcseconds);
		var offset = (-1 * d.getTimezoneOffset() / 60);
		var offsetstring = '';
		if (offset > 0) { offsetstring = '+' + offset; }
		if (offset < 0) { offsetstring = offset; }
		
		// Default to showing the time only
		var datestring = pad(d.getHours()) + ':' + pad(d.getMinutes()) + ' UTC' + offsetstring;
		var titlestring = pad(d.getUTCHours()) + ':' + pad(d.getUTCMinutes()) + ' UTC';
		
		// But check for different formatting in case there is a day of the week given inside the span
		if (!v.textContent.match(/^\d/)) {
			datestring  = days[d.getDay()] + ' ' + datestring;
			titlestring = days[d.getUTCDay()] + ' ' + titlestring;
		}
		
		// Show result
		$(v).html('<span style="cursor:help; border-bottom:1px dotted silver;" title="'+titlestring+'">'+datestring+'</span>');
	});
}
Get MetaBattle Premium
Enjoy an ad-free experience & support the website, for less than $1 per month! Upgrade to Premium