Skip to content

Instantly share code, notes, and snippets.

@hippietrail
Created October 19, 2012 06:24
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 hippietrail/3916512 to your computer and use it in GitHub Desktop.
Save hippietrail/3916512 to your computer and use it in GitHub Desktop.
Sort Stack Exchange tags by relevance
var $c = $('#h-related-tags').parent().contents(),
s = null,
arr = [];
$c.each(function(i, e) {
var $sl, counts;
if (e.tagName === 'A') {
s = i;
} else if (e.tagName == 'BR') {
$sl = $c.slice(s, i + 1);
counts = $.makeArray(
$sl.find('.item-multiplier-count').map(function() {
return parseInt(this.textContent, 10);
})
);
counts = [1, 1].concat(counts).splice(counts.length, 2);
arr.push(
[$sl].concat(
counts[0] / counts[1]
)
);
}
});
arr.sort(function(a, b) {
return b[1] - a[1];
});
arr.forEach(function(e, i) {
$('#h-related-tags').parent().append(e[0]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment