User:Majr/fileNuke.js

function deleteFiles( files, count ) { if ( count === undefined ) { count = 0; }	if ( !files[count] ) { return; }	var api = new mw.Api api.get( {		action: 'query',		list: 'backlinks',		blredirect: 1,		bltitle: files[count],		bllimit: 5000	} ).done( function( data ) {		var backlinks = data.query ? data.query.backlinks : null;		if ( !backlinks.length || ( backlinks.length === 1 && backlinks[0].title === files[count] ) ) {			api.post( { action: 'delete', token: mw.user.tokens.get( 'editToken' ), title: files[count], reason: 'Unused file' } ).done( function { console.info( 'Deleted:', files[count] ); deleteFiles( files, count + 1 ); } ).fail( function( _, error ) { console.warn( error.error.info ); } );		} else {			console.info( 'Skipped:', files[count] );		}	} ).fail( function( _, error ) {		console.warn( error.error.info );	} ).always( function {		deleteFiles( files, count + 1 );	} ); }

if ( $( '#gallery-list' ).length ) { $( '#gallery-list' ).append( ' Delete ' ); var $button = $( '#gallery-list > .delete' ); $button.click( function {		deleteFiles( $( '#gallery-list > textarea' ).val.split( '\n' ) );	} ); }