MediaWiki:Group-user.js

From Halopedia, the Halo wiki

Revision as of 20:44, January 14, 2021 by Porplemontage (talk | contribs)

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 registered users only */

/* Clean-up the file extension for new uploads and fix mobile */
$(function() {
	if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload' && !$('#wpForReUpload').length && !$('.warning').length) {
		if (mw.config.get('wgMFMode')) {
			$("#wpUploadFile").change(function() {
				var ogFileName = $("#wpUploadFile").val().split('\\').pop();
				$('#wpDestFile').val(ogFileName);
			});
			$("#wpUploadFileURL").change(function() {
				var ogFileName = $("#wpUploadFileURL").val().split('/').pop();
				$('#wpDestFile').val(ogFileName);
			});
		}
		$('input[name=wpUpload]').click(function() {
			var file = $('#wpDestFile').val().replace(/\.+$/, '');
			if (file.includes('.')) {
				var fileName = file.substr(0, file.lastIndexOf('.')).replace(/\.+$/, '');
				var fileExt = file.split('.').pop().toLowerCase();
				var regex = new RegExp('(\.' + fileExt + ')+$', 'i');
				fileName = fileName.replace(regex, '');
				if (fileExt == 'jpeg')
					fileExt = 'jpg';
				$('#wpDestFile').val(fileName + '.' + fileExt);
			}
		});
	}
});

/* Username inserts for Template:USERNAME */
$(function() {
	if (typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || mw.config.get('wgUserName') === null) return;
	$('span.insertusername').each(function() {
		$(this).text(mw.config.get('wgUserName'));
	});
});

/* Upload page script */
$(function() {
	if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload')
		mw.loader.load('/index.php?title=MediaWiki:HalopediaUpload.js&action=raw&ctype=text/javascript');
});