Last active
October 13, 2015 15:08
-
-
Save vasi/4214455 to your computer and use it in GitHub Desktop.
Sort Metafilter comments
This file contains hidden or 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
(function(){ | |
var resort = []; | |
$(".comments span[id^='favcnt']").each(function(i, e) { | |
if ($(e).html() != '') { | |
var grp = $(e).parents('.comments').prev('a'). | |
nextUntil('a').andSelf(); | |
var fav = parseInt($(e).text().split(' ')[0].trim()); | |
resort.push({ 'fav': fav, 'elems': grp }); | |
} | |
}); | |
resort.sort(function(a,b) { return a['fav'] - b['fav'] }); | |
var target = $('.copy + br'); | |
$(resort).each(function(i, e) { | |
$(e['elems']).insertAfter(target); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bookmarklet:
javascript:void((function() {var s=document.createElement('script');s.type='text/javascript';s.src='https://raw.github.com/gist/4214455/862e5fb4aeb8169705169f386fbc9aa8964c77aa/gistfile1.txt';document.getElementsByTagName('head')[0].appendChild(s);})())