User:Ozuzanna/wantedfiles.js

/* Quick image macro source comment deletion */
 * (function($, mw) {

if (mw.config.get('wgCanonicalSpecialPageName') == "Wantedfiles") { $('.mw-spcontent').find('p').first.append(' Delete Comments');

$('#btn-delete').click(function {   $('.special > li').each(function { var page = $(this).children('a').first.text; new mw.Api.get({       action: 'query',	    list: 'imageusage',        iutitle: page,	    iulimit: 5000        }) .done(function(d) {	     if (!d.error) {            var data = d.query;		    for (var i in data.imageusage) {		      if (data.imageusage[i].title.split('Talk:').length == 2 || data.imageusage[i].title.split('User_blog_comment:').length == 2)                del(data.imageusage[i].title);            }		  }		  else {	  	    console.log('Failed to get image usage for '+page+' : '+d.error.code);	      }        }) .fail(function {         console.log('Failed to get image usage!');        }); }); });	  function del(pagename) { new mw.Api.post({   format: 'json',    action: 'delete',    watchlist: 'nochange',    title: pagename,    reason: 'Defunct image comment',    token: mw.user.tokens.get('editToken')    }) .done(function(d) {      if (!d.error) {        console.log('Deletion of '+pagename+' successful!');      }	  else {        console.log('Failed to delete '+pagename+': '+ d.error.code);      }		    }) .fail(function {     console.log('Failed to delete '+page+'!');    }); setTimeout(d,1000); } }

}) (this.jQuery, this.mediaWiki);