Skip to content

Instantly share code, notes, and snippets.

@devheedoo
Created November 7, 2019 08:48
Show Gist options
  • Save devheedoo/69b839aa55784677acf9846c50f558d1 to your computer and use it in GitHub Desktop.
Save devheedoo/69b839aa55784677acf9846c50f558d1 to your computer and use it in GitHub Desktop.
Go to the most pointed answer in GitHub Issue
function goToMostPointedAnswerInGithubIssue() {
const pointsWithIndex = [];
const gEmojis = document.querySelectorAll('g-emoji');
gEmojis.forEach((gEmoji, index) => {
// find +1 point emoji elements
if (gEmoji.getAttribute('alias') === '+1') {
const splitedHtml = gEmoji.parentElement.innerHTML.split('</g-emoji>');
const point = Number(splitedHtml[splitedHtml.length - 1].trim());
if (point > 0) {
pointsWithIndex.push({ point, index });
}
}
});
const bestAnswerInfo = pointsWithIndex.reduce((prev, next) => prev.point > next.point ? prev : next);
const bestAnswerId = gEmojis[bestAnswerInfo.index]
.closest('.timeline-comment-group')
.getAttribute('id');
location.href = location.href.split('#')[0] + `#${bestAnswerId}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment