7

If you have the privilege to delete answers with negative score, a delete button is shown in the flag queue:

Flag queue delete button

But if the answer did not have a negative score before and I downvoted it then there is no delete button:

Flag queue no delete button

I would have to refresh the page to see the delete button. But then I lose the focus on that post or it may not even be in the current list any more and I would have to search it.

Can this button be added on-the-fly when I downvote?

2
  • Click share, Ctrl+C, Alt+D, Ctrl+V, enter > F5 (not that I'd mind your proposal, if there's time to spare for implementing it...) Commented Mar 8, 2014 at 9:38
  • +1 - also, I'd like a combined "downvote, close, delete-when-closed" batch button on questions :-)
    – Kerrek SB
    Commented Mar 8, 2014 at 11:56

1 Answer 1

2

I've added a client-side implementation of this feature into the Stack Overflow Unofficial Patch v1.10.

In case you're curious, here's the JavaScript code that does it:

if ( ! $('body.tools-page.flag-page').length ) return;
if ( SOUP.userRep < ( SOUP.isBeta ? 4000 : 20000 ) ) return;

var html = '<input title="vote to delete this answer" class="delete-post" value="delete answer" type="button">';

SOUP.hookAjax( /^\/posts\/\d+\/vote\/[023]\b/, function ( event, xhr, settings ) {
    var score = $.parseJSON( xhr.responseText ).NewScore;
    var pid = Number( settings.url.replace( /^\/posts\/(\d+)\/.*/, '$1' ) );

    // if it's not an answer, do nothing
    if ( ! $('#flagged-' + pid + ' #answer-' + pid).length ) return;

    // find *all* the delete buttons/links; there may be several!
    var button = $('[id="delete-post-' + pid + '"]');

    if ( score >= 0 ) button.hide();
    else if ( button.length ) button.show();
    else $(html).attr('id', 'delete-post-' + pid).insertAfter('#flagged-' + pid + ' .flag-post-button').before(' ');
} );

The SOUP.hookAjax() function is a small piece of utility code that monitors the jQuery AJAX requests used to submit post up/downvotes. If an answer is upvoted (or un-downvoted) to a positive score from the review view, the event handler above hides the delete button; if it's downvoted to a score of zero or less, it re-shows it, or, if necessary, injects its own "fake" (but fully functional!) delete button.

(For an official fix, it would probably be easier to just include the delete buttons in the HTML for all answers, but hide it by default for those with a positive score. I can't do that in a user script, so I have to hardcode the button HTML into the script.)

Not the answer you're looking for? Browse other questions tagged .