User:Majr/fileNuke.js

function deleteFiles( files, count ) { if ( count === undefined ) { count = 0; }	if ( !files[count] ) { return; }	$.get( '/api.php', {		format: 'json',		action: 'query',		list: 'backlinks',		blredirect: 1,		bltitle: files[count],		bllimit: 5000	} ).done( function( data ) {		var backlinks = data.query.backlinks;		if ( !backlinks.length || ( backlinks.length === 1 && backlinks[0].title === files[count] ) ) {			$.post( '/api.php', { format: 'json', action: 'delete', token: mw.user.tokens.get( 'editToken' ), title: files[count], reason: 'Unused file' } ).done( function( data ) { if ( data.error ) { console.warn( data.error.info ); } else { console.info( 'Deleted:', files[count] ); }				deleteFiles( files, count + 1 ); } );		} else {			console.info( 'Skipped:', files[count] );			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' ) );	} ); }