Created
June 16, 2021 20:53
-
-
Save jasonandmonte/2201fa5597d4503f25de04901a4e43e7 to your computer and use it in GitHub Desktop.
Sorts Stack Overflow answers by votes including the accepted answer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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