Jump to content

User:Zzuuzz/scripts/badimagelist.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// Sorts the list and highlights any redirects at MediaWiki:Bad image list

function sortBIL() {
	var box = $('#wpTextbox1');
	var content = box.val();
	var start = content.indexOf('*');
	var prepend = content.substr(0, start);
	var items = content.substr(start).split(/\*/);
	box.val(prepend + items.sort(sortBIL2).join('*'));
}

function sortBIL2(a, b) {
	return a.replace(/\./g, "\t").localeCompare(b.replace(/\./g, "\t"));
}

$(document).ready(function () {
	
	if( mw.config.get('wgPageName') === 'MediaWiki:Bad_image_list' ) {
		$('.mw-redirect').css( {'background-color': 'yellow', 'font-weight': 'bold'} );
		if ( 'edit' === mw.config.get( 'wgAction' ) || 'submit' === mw.config.get( 'wgAction' ) ) {
			mw.util.addPortletLink('p-cactions', 'javascript:sortBIL()', 'Sort');
		}
	}
});