Skip to content

Instantly share code, notes, and snippets.

@jasonandmonte
Created June 16, 2021 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonandmonte/2201fa5597d4503f25de04901a4e43e7 to your computer and use it in GitHub Desktop.
Save jasonandmonte/2201fa5597d4503f25de04901a4e43e7 to your computer and use it in GitHub Desktop.
Sorts Stack Overflow answers by votes including the accepted answer.
// ==UserScript==
// @name Stack Overflow - Sort By Votes
// @version 1.0.0
// @description Ignores accepted answer and sorts answers by most votes
// @author https://github.com/jasonandmonte
// @match https://stackoverflow.com/questions/*
// @grant none
// ==/UserScript==
(() => {
const sorted = [...document.getElementById('answers').children]
.filter(item => item.id.includes('answer-'))
.sort((e1, e2) => e2.dataset.score - e1.dataset.score);
// Add the header element to the top
[document.getElementById('answers-header'), ...sorted].forEach((elm) => {
document.getElementById('answers').appendChild(elm)
})
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment