Created
November 7, 2019 08:48
-
-
Save devheedoo/69b839aa55784677acf9846c50f558d1 to your computer and use it in GitHub Desktop.
Go to the most pointed answer in GitHub Issue
This file contains 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
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