5

Stack Exchange often places the accepted answer on top of all other answers.

I often get tricked into implementing the first answer, only to realize that it is vastly inferior to the second answer, with has much more upvotes. (example)

So, I am looking for an extension that would sort answer strictly by votes.
The order would not be affected by an answer being accepted or not.

Requirements:

  • Works on Firefox
  • Free, ideally open source
  • Have you checked with StackApps, Nicolas? I cannot access my home machine currently (OOO=OutOfOffice), but remember there was a quite extensive SE-specific UserScript I've installed there. Not sure whether it includes what you're after, as I rarely noticed the described problem – which might be due to the fact the script takes care of exactly that :) Maybe Shub adds it to his SE Additional Optional Features when asked. – Izzy Apr 1 '15 at 9:06
  • @Izzy: Searching for "accepted" does not lea to any obvious result there. Nor does searching for "sort" :-/ – Nicolas Raoul Apr 1 '15 at 9:22
  • I'm just walking all those 17 pages manually. If I find something, I'll put a note here – if not, I'll check at home in the evening. Will let you know. – Izzy Apr 1 '15 at 9:23
  • Lol @Izzy why not? Not at home right now but doesn't the 'votes' sort do what you want...? I can't test it right now, so I might be wrong. – ᔕᖺᘎᕊ Apr 1 '15 at 11:18
  • @ᔕᖺᘎᕊ I'm not the OP – and no, the 'votes' sort cannot lookup my machine at home :) But the script I had in mind doesn't do what Nicolas is after: SE Modifications does a real lot of useful things, but not that... – Izzy Apr 1 '15 at 14:14
5

I've made a userscript to do this - it adds another sort button on the answers tab:

enter image description here

I've tested it on Firefox and Chrome on this question.

It will take the votes and sort them in descending order without taking into account which is the accepted answer (which it seems the 'votes' tab does currently).

To use, install Greasemonkey (on Firefox) or Tampermonkey (on Chrome) and install the script:

// ==UserScript==
// @name         Sort by votes, properly...
// @namespace    http://stackexchange.com/users/4337810
// @version      1.1
// @description  Adds a new option on questions to sort answers by votes *ignoring the accepted answer* - unlike the current 'votes' tab.
// @author       ᔕᖺᘎᕊ (http://stackexchange.com/users/4337810)
// @match        *://*.stackexchange.com/*
// @match        *://*.stackoverflow.com/*
// @match        *://*.superuser.com/*
// @match        *://*.serverfault.com/*
// @match        *://*.askubuntu.com/*
// @match        *://*.stackapps.com/*
// @match        *://*.mathoverflow.net/*
// @grant        none
// ==/UserScript==

setTimeout(function() {
    if ( $('.answer').length ) {
        $('.answer').each(function() {
            votes = $(this).find('.vote-count-post').text();
            $(this).attr('data-votes', votes); //add a 'votes' attribute to all the questions
        });

        var $wrapper = $('#answers');

        $('#answers-header').insertBefore('#answers');
        $('#tabs').append('<a href="javascript:void(0)" id="realVotesTab" title="Answers with the highest score first (ignoring accepted answers!)">real votes</a>');

        $('#realVotesTab').on('click', function() {
            $('#tabs a').removeClass('youarehere');
            $(this).addClass('youarehere');       
            //Thanks: https://stackoverflow.com/a/14160529/3541881
            $wrapper.find('.answer').sort(function(a, b) {
                return +b.getAttribute('data-votes') - +a.getAttribute('data-votes');
            }).prependTo($wrapper);
        });    

        //Comment out the next 3 lines if you do not want the 'real votes' tab to automatically be chosen when yuo first arrive at a question (ie. prepend "//" to the next 3 lines)
        if(document.URL.indexOf('?answertab=') == -1) {
           $('#realVotesTab').trigger('click');
        }
    }
}, 100);

Note: This is largely based on my previous script to sort bounties :)

  • +1 Works great! Would it be possible to show the "real votes" tab by default, without having to click on it? Thanks a lot! – Nicolas Raoul Apr 6 '15 at 1:48
  • @NicolasRaoul Done; if you want to stop it from auto-choosing the real votes tab - just comment out the lines where it says (near the bottom) :) – ᔕᖺᘎᕊ Apr 6 '15 at 9:27
  • 1
    Thanks a lot! Perfect :-D – Nicolas Raoul Apr 6 '15 at 9:40
  • Is this available for Stylish, by any chance? – SarahofGaia Aug 3 '15 at 1:24
  • @SarahofGaia no sorry :/... – ᔕᖺᘎᕊ Aug 3 '15 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.