Difference between revisions of "Common.js"
Line 17: | Line 17: | ||
content.style.display = "block"; | 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>'); | ||
}); | }); | ||
} | } |
Revision as of 18:24, 8 February 2023
$(function() { $(".build-template-button").click(function(){ navigator.clipboard.writeText($(this).prev().text()); alert("Template code copied!"); }); }); 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
Enjoy an ad-free experience & support the website, for less than $1 per month! Upgrade to Premium