Jump to content

User:DannyS712 test/PC.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.
//<nowiki>
$(function (){
var PC_config = {
	name: '[[User:DannyS712/Polluted categories|Polluted categories.js]]',
	version: 1.0,
	debug: true
};
var PC_summary = 'SUMMARY with ' + PC_config.name + ' (version ' + PC_config.version + ')';
var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';

mw.loader.using( 'mediawiki.util', function () {
	importScript( 'User:DannyS712 test/page.js' );
	if ( mw.config.get( 'wgPageName' ) === "Wikipedia:Database_reports/Polluted_categories") {
	    $(document).ready( function () { 
	    	mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'Polluted categories', 'ca-polluted', 'TOOLTIP');
	    	$('#ca-polluted').on('click', function() {
	        	Polluted_categories();
	    	} );
	    } );
	}
} );
function Polluted_categories(){
	var content1 = get_page( mw.config.get( 'wgPageName' ) );
	if (PC_config.debug) console.log( content1 );
	var content2 = content1.replace( /\|-\n\| (\d*)\n\| {{dbr link\|1=(.*)}}/g, '"$2",');
	if (PC_config.debug) console.log( content2 );
	var content3 = content2.replace( /(.*\n)*! Category\n/i, '{\n"Pages": [');
	if (PC_config.debug) console.log( content3 );
	var content4 = content3.replace ( /,\n\|}/, "\n] }");
	if (PC_config.debug) console.log( content3 );
	var content5 = content4.replace ( /_/g, " ");
	if (PC_config.debug) console.log( content5 );
	var as_JSON = JSON.parse( content5 );
	if (PC_config.debug) console.log( as_JSON );
	var array = as_JSON.Pages;
	console.log( array );
	
	var page = "";
	for (var iii = 0; iii < array.length; iii++){
		page = array[iii];
		if (/AfC submissions.*/.test(page)) console.log( "Skip: AfC" );
		else {
			console.log( page );
		}
	}
}
});
//</nowiki>