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
5
  • 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
    Commented Apr 1, 2015 at 9:06
  • @Izzy: Searching for "accepted" does not lea to any obvious result there. Nor does searching for "sort" :-/
    – Nicolas Raoul
    Commented Apr 1, 2015 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
    Commented Apr 1, 2015 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. Commented Apr 1, 2015 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
    Commented Apr 1, 2015 at 14:14

1 Answer 1

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 :)

5
  • +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
    Commented Apr 6, 2015 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) :) Commented Apr 6, 2015 at 9:27
  • Is this available for Stylish, by any chance? Commented Aug 3, 2015 at 1:24
  • @SarahofGaia no sorry :/... Commented Aug 3, 2015 at 8:29
  • Okay. It's okay. Commented Aug 4, 2015 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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