<!-- thumbnail: https://i.sstatic.net/2lUKi.png --> <!-- version: 0.6 --> <!-- excerpt: Allows sorting answers by code length on Programming Puzzles & Code Golf Stack Exchange. --> ## Screenshot ![Screenshot of Code Golf SE answer sorter user script][1] ## About This script adds a "shortest" tab to pages on the [Programming Puzzles & Code Golf](http://codegolf.stackexchange.com) Stack Exchange site. Clicking the tab will sort answers in decreasing order by the length of the first code block in the answer. It was written as a simple replacement for the [original codegolf.SE user script](https://stackapps.com/questions/2048/code-golf-userscript-enhancement-pack) that broke with the new Stack Exchange top bar. The new tab functions pretty much like the normal "active", "oldest" and "votes" tabs, except for a couple of small quirks: * The information about whether or not the new tab is selected is stored in your browser. It is thus not synchronized across multiple browsers or computers. * If there are so many answers (over 30, currently) that they get split over multiple pages, the script will only re-sort the answers on the currently visible page; it will not pull answers from other pages, even if they might have a lower golf score. * Related to the above, since the choice of which answers are visible on the page may depend on the actual server-side sorting order active before the script runs, this is indicated by a small dashed yellow line under the corresponding tab. To change the server-side sorting mode, click one of the other tabs and then click "shortest" again. * Deleted answers and answers with a voting score of -3 or less are always sorted to the end of the page. (Technically, the sorting code ignores them entirely.) Answers that include a code block, however long, are always sorted before answers that don't. Answers with equal golf score are sorted randomly. The accepted answer is currently _not_ always sorted first. ###License This script is released into the public domain per the [Creative Commons CC0 public domain dedication](//creativecommons.org/publicdomain/zero/1.0/). Feel free to do whatever you want with it. ###Download / Install This user script is [hosted on GitHub][info]. If you have a suitable user script management extension (such as [GreaseMonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/) for Firefox or [Tampermonkey](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo) for Chrome) installed, clicking the ["download / install"][install] button below should bring up a dialog asking you if you want to install this user script: > # [<kbd>Download / Install</kbd>][install] > <sup>[view source][source]</sup> For more information on how to install user scripts, see the [script tag wiki](https://stackapps.com/tags/script/info). ###Compatibility This user script has been tested on Mozilla Firefox and Google Chrome. It should work on any browser with a compatible user script API, including Opera and Safari. Please report any incompatibilities you may find. ###Links * The original [Code Golf UserScript Enhancement Pack](https://stackapps.com/questions/2048/code-golf-userscript-enhancement-pack) by Nathan Osman; apparently no longer maintained, does not work with the new SE top bar. * [Show length of code blocks](https://stackapps.com/questions/4342/show-length-of-code-blocks-mainly-for-codegolf-se) by Doorknob; works very nicely together with this script. * [Discussion of this script on Programming Puzzles & Code Golf Meta SE.](http://meta.codegolf.stackexchange.com/questions/900/we-have-a-new-user-script) [install]: https://gist.github.com/vyznev/9b55e1f96ee129d53466/raw/267df3d186d00e9ae874ff911e5f20ed6078529d/codegolf_sorter.user.js [info]: https://gist.github.com/vyznev/9b55e1f96ee129d53466 [source]: https://gist.github.com/vyznev/9b55e1f96ee129d53466 [1]: https://i.sstatic.net/bME6A.png