It's mostly dirty jQuery scripting, so it might break whenever Quora updates their markup.
Last active
March 18, 2016 16:16
-
-
Save florian/dd408a8399aebba43c04 to your computer and use it in GitHub Desktop.
Quora user profile: Sort answers by upvotes
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
// We need this method because Quora displays 1500 upvotes as "1.5k" | |
function parseUpvotes (str) { | |
if (match = str.match(/(\d+)\.(\d+)/)) { | |
return Number(match[1]) * 1000 + Number(match[2]) * 100 | |
} else { | |
return parseInt(str, 10) | |
} | |
} | |
function sortByUpvotes () { | |
// Prepending is important, it will only move the elements and that way we don't lose the event handlers | |
$('.PagedList.UserAnswerProfileFeed').prepend($('.pagedlist_item').sort((a,b) => { | |
var x = $(a).find('.count').html() | |
var y = $(b).find('.count').html() | |
return parseUpvotes(y) - parseUpvotes(x) | |
})) | |
} | |
// This might take a while | |
function loadAllAnswers (callback) { | |
var total = parseInt($('.list_header').text().replace(",", ""), 10) | |
var timer = setInterval(() => { | |
console.log("%s / %s answers loaded", $('.pagedlist_item').length, total) | |
if ($('.pagedlist_item').length >= total) { | |
clearInterval(timer) | |
callback() | |
} else { | |
window.scrollTo(0,document.body.scrollHeight) | |
} | |
}, 1000) | |
} |
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
// Sorting currently loaded answers by upvotes | |
sortByUpvotes() | |
// First loading all answers and then sorting them by upvotes | |
loadAllAnswers(() => { | |
sortByUpvotes() | |
window.scrollTo(0, 0) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment