Skip to content

Instantly share code, notes, and snippets.

@funkyremi
Created February 15, 2019 16:19
Show Gist options
  • Save funkyremi/080f2f84fb275c609484b49b46d146a4 to your computer and use it in GitHub Desktop.
Save funkyremi/080f2f84fb275c609484b49b46d146a4 to your computer and use it in GitHub Desktop.
Auto scroll to Github best comment
// Auto scroll to Github best comment
// Choose one of the following method (Bookmark toolbar link or Browser console)
// Minified code (drag and drop to your bookmarks)
javascript:var bestCommentId;var bestScore=0;Array.from(document.querySelectorAll(".js-targetable-comment")).forEach(item=>{if(item.querySelector("button.reaction-summary-item")){let commentScore=0;Array.from(item.querySelectorAll("button.reaction-summary-item")).forEach(i=>{if(!!i.innerText){commentScore+=Number(i.innerText.replace(/\D/g,''))}});if(commentScore>bestScore){bestScore=commentScore;bestCommentId=item.id}}});console.log('Comment score',bestScore);location.href=`#${ bestCommentId }`;
// Original code (copy paste in your browser console)
var bestCommentId;
var bestScore = 0;
Array.from(document.querySelectorAll(".js-targetable-comment")).forEach(item => {
if (item.querySelector("button.reaction-summary-item")) {
let commentScore = 0;
Array.from(item.querySelectorAll("button.reaction-summary-item")).forEach(i => {
if (!!i.innerText) {
commentScore += Number(i.innerText.replace(/\D/g, ''));
}
});
if (commentScore > bestScore) {
bestScore = commentScore;
bestCommentId = item.id;
}
}
});
console.log('Comment score', bestScore);
location.href = `#${bestCommentId}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment