User:JJMC89/scripts/T210739.js

// Original source: zh:MediaWiki:Gadget-T210739.js // Original author: Xiplus // Modifications: JJMC89

$.when( $.ready, mw.loader.using( ['oojs-ui', 'mediawiki.api'] ) ).then( function {

if (document.getElementsByName( 'wpDeleteAndMove' ).length < 1) { return; }	var formattedNamespaces = mw.config.get( 'wgFormattedNamespaces' ); var desination_ns = Number(document.getElementsByName( 'wpNewTitleNs' )[0].value); var destination_title = document.getElementsByName( 'wpNewTitleMain' )[0].value; var button = new OO.ui.ButtonWidget( {		flags: [ 'primary', 'destructive' ],	   label: 'Delete the destination page',	    icon: 'trash',	    title: 'Use the API to delete the destination page'	} ).on('click', function  {		var target = formattedNamespaces[desination_ns];		if (target !== '') {			target += ':';		}		target += destination_title;	    new mw.Api.postWithEditToken({ action: 'delete', title: target, reason: 'G6: Deleted to make way for move' }).then(function(e) { mw.notify( 'Successfully deleted ' + target ); }, function(e) { mw.notify( 'An error occurred while deleting：' + e ); });	});	$(document.getElementsByName( 'wpMove' )[0].parentElement.parentElement).append( button.$element ); if ( desination_ns % 2 === 0 ) { // Subject namespaces var talk_target = formattedNamespaces[desination_ns + 1] + ':' + destination_title; new mw.Api.get( {		   action: 'query',		    titles: [ talk_target ],		} ).then( function( ret ) {		    $.each( ret.query.pages, function { if ( this.missing !== '' ) { // Talk page exists var talk_button = new OO.ui.ButtonWidget( {						flags: [ 'destructive' ],					   label: "Delete the destination page's talk page",					    icon: 'trash',					    title: "Use the API to delete the destination page's talk page"					} ).on('click', function  {					    new mw.Api.postWithEditToken({ action: 'delete', title: talk_target, reason: 'G6: Deleted to make way for move' }).then(function(e) { mw.notify('Successfully deleted ' + talk_target); }, function(e) { mw.notify('An error occurred while deleting：' + e); });					});					button.$element.append( talk_button.$element ); }		   } );		}, function( error ) {		    mw.notify( 'An error occurred while determing if the talk page exists：' + error );		} );

} } );