Skip to content

Instantly share code, notes, and snippets.

@BrynM
Last active May 27, 2019 04:00
Show Gist options
  • Save BrynM/d6d52bd8d7c7a7a75fbc251f68d35ed1 to your computer and use it in GitHub Desktop.
Save BrynM/d6d52bd8d7c7a7a75fbc251f68d35ed1 to your computer and use it in GitHub Desktop.
gt11Rankings
// get top-level entries exclusing collapsed
var entries = $('.commentarea > .sitetable > .comment:not(.collapsed) > .entry');
var final = [];
// loop through the entries recording author, score, and page position
for (var i = 0; i < entries.length; i++) {
var tagline = entries[i].querySelector('.tagline');
// account for which score to take depending on voted state (ug)
var score = entries[i].classList.contains('likes') ? tagline.querySelector('.score.likes') : entries[i].classList.contains('dislikes') ? tagline.querySelector('.score.dislikes') : tagline.querySelector('.score.unvoted');
final.push({
"author": tagline.querySelector('.author').text,
"score": score.getAttribute('title'),
"pageOrder": i
});
}
// Sort based on score and if scores match, sort based on page postion
final.sort((a, b) => a.score == b.score ? a.pageOrder - b.pageOrder : b.score - a.score);
// assemble the output CSV text
rankings = 'place, author, score, pagePosition\n';
for (var i = 0; i < final.length; i++) {
rankings += (i+1)+', '+final[i].author+', '+final[i].score+', '+final[i].pageOrder+'\n';
}
// print the output CSV text
console.log('\n'+rankings+'\n');
@BrynM
Copy link
Author

BrynM commented May 27, 2019

Be sure to collapse the removed top-level comments first. Any ties are broken by comparing who has the uppermost position on the page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment