Logo Albion iconAlbion Online AoC iconAshes of Creation Deadlock iconDeadlock GW2 iconGuild Wars 2 TL iconThrone & Liberty

Difference between revisions of "Common.js"

 
Line 1: Line 1:
 
$(function() {
 
$(function() {
 
$(".build-template-button").click(function(){
 
$(".build-template-button").click(function(){
navigator.clipboard.writeText($(this).prev().text());
+
var $this = $(this);
alert("Template code copied!");
+
navigator.clipboard.writeText($this.prev().text());
 +
$this.text('Copied');
 +
setTimeout(function() {
 +
$this.text('Copy Template Code');
 +
}, 2000);
 
});
 
});
 
});
 
});

Latest revision as of 20:03, 15 August 2023

$(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
Split Metabattle Logo