User:DannyS712/Change status.js

// Install this version with: //  // // If forking this script, please note my contributions / give me credit $(function { var CS_config = {	name: 'Change status.js',	version: 1.1,	debug: true }; var CS_summary = 'Change status with ' + CS_config.name + ' (version ' + CS_config.version + ')'; var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';

mw.loader.using( 'mediawiki.util', function {    $(document).ready( function  { if ( mw.config.get('wgNamespaceNumber') === 104 ) { mw.util.addPortletLink ( 'p-cactions', 'javascript:void(0)', 'Change status', 'ca-change-status', 'Change status'); $('#ca-change-status').on('click', function {       		change_status;    		} ); }   } ); } ); function change_status{ var name = mw.config.get( 'wgPageName' ); var page = get_page ( name ); var this_user = mw.config.get( 'wgUserName' ); if (CS_config.debug) console.log ( page ); var status = page.replace(/(?:.|\n)*()(?:.|\n)*/, '$1'); var status_user = status.replace(/.*?user="(.*?)" \/>/, '$1'); var status_level = status.replace(/.*?level="(\d+)" user=".*\/>/, '$1');	console.log( status, status_user, status_level, this_user );	var new_status, new_page;	if (status_level === "1" || status_level === "2"){		console.log('Status is 1 or 2');		new_status = '';		new_page = page.replace(//, new_status);		CS_summary = 'Mark as proofread with ' + CS_config.name + ' (version ' + CS_config.version + ')';	} else if (status_level === "3" && status_user != this_user){		console.log('Status is 3, can be validated');		new_status = '';		new_page = page.replace(//, new_status);		CS_summary = 'Mark as validated with ' + CS_config.name + ' (version ' + CS_config.version + ')';	}	if (CS_config.debug) console.log ( new_status, new_page );	if (page === new_page) return; set_new ( name, new_page ); } function get_page( name ){ var page_to_get = { action: 'query', titles: name, prop: 'revisions', rvprop: 'content', format: 'json', formatversion: 2 };   var result = null; $.ajax({		url: scriptUrl,		type: 'get',		data: page_to_get,		dataType: 'json',		async: false,		success: function(page) {			if (CS_config.debug) console.log( page );	   	result = page.query.pages["0"].revisions["0"].content;	    	if (CS_config.debug) console.log( result );		} 	}); return result; } function set_new ( page, new_content ){ console.log( page, new_content ); var to_send = { action: 'edit', title: page, text: new_content, summary: CS_summary, token: mw.user.tokens.get( 'csrfToken' ) };   console.log( to_send ); $.when(       $.post( scriptUrl, to_send, function( response ){ } )    ).done( function {		location.reload;    } ); } });