User:Shining-Armor/scripts/SpeedyDeleteComments.js

/** * SpeedyDeleteComments.js * * Written by User:Shining-Armor * * Based off of a script by User:Sactage */

var SpeedyDeleteComments = {}; SpeedyDeleteComments.options = { 'None': 'None', 'Flaming': 'Flame', 'Inappropriate': 'Inappropriate', 'Off-topic': 'Off-topic', 'Spam/Nonsense': 'Spam' }; SpeedyDeleteComments.html = '\  \ Delete (Speedy)'; SpeedyDeleteComments.generateSelector = function { var selector = ''; for ( var i in this.options ) { selector += '' + this.options[i] + ' '; }   return selector; }; SpeedyDeleteComments.result = function( result ) { if ( result === true ) { alert( 'Comment deleted! '); } else { alert( 'Failed to delete comment!' ); } }; SpeedyDeleteComments.deletePage = function( comment, reason ) { comment = comment.split( '/wiki/' )[1]; comment = comment.split( '?permalink' )[0];

$.ajax( {       url: '/api.php',        type: 'POST',        data: {            action: 'delete',             title: comment,             reason: reason,             indexpageids: '',             token: mw.user.tokens.values.editToken        },        success: function {            SpeedyDeleteComments.result( true );        },        error: function {            SpeedyDeleteComments.result( false );        }    } ); }; SpeedyDeleteComments.init = function { $( '#article-comments-ul li .tools' ).each( function {       $( this ).append( SpeedyDeleteComments.html );        $( '.speedy-delete-comments' ).html( SpeedyDeleteComments.generateSelector );        $( this ).find( '.speedy-delete-button' ).on( 'click', function { var url = $( this ).parent.parent.parent.find( '.permalink' ).attr( 'href' ); var reason = $( this ).parent.find( 'select' ).val; SpeedyDeleteComments.deletePage( url, reason ); } );   } ); }; $( document ).ready( function {    if ( mw.config.get( 'wgNamespaceNumber' ) === 500 ) {        if ( mw.config.get( 'wgUserGroups' ).indexOf( 'sysop' ) > -1 ) {            SpeedyDeleteComments.init;        }    } } );