Jump to content

User:Evad37/Watchlist-hideAWB.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.
function setupHideAWB() {
	// Add a class to list items with AWB in edit summary
	$( "a[title='Wikipedia:AWB'], a[title='Wikipedia:AutoWikiBrowser']" ).closest("li, tr").addClass("watchlist-awb-edit");

	// Show/hide AWB edits
	mw.util.addPortletLink( 'p-cactions', '#', 'Hide AWB', 'ca-hideAWB', "Hide AWB edits" );
	mw.util.addPortletLink( 'p-cactions', '#', 'Show AWB', 'ca-showAWB', "Show AWB edits" );
	
	// 'Hidden by default' option
	if ( window.awbHiddenByDefault ) {
		$(".watchlist-awb-edit").hide();
		$('#ca-hideAWB').hide();
	} else {
		$('#ca-showAWB').hide();
	}
	
	$('#ca-hideAWB').on('click', function() {
		$(".watchlist-awb-edit").hide();
		$('#ca-showAWB').show();
		$('#ca-hideAWB').hide();
		return false;
	});
	
	$('#ca-showAWB').on('click', function() {
		$(".watchlist-awb-edit").show();
		$('#ca-showAWB').hide();
		$('#ca-hideAWB').show();
		return false;
	});

}

if( mw.config.get('wgNamespaceNumber') === -1 ) {
	// Only operate in Special: namespace
	$.when( mw.loader.using( ['mediawiki.util'] ), $.ready).done( setupHideAWB );
}