Last active
June 29, 2022 14:31
-
-
Save AnweshGangula/4fdcc804bcaa0636f4987e8b3a553953 to your computer and use it in GitHub Desktop.
Highlight Current Users Answer in Stack overflow
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
// Copy paste this code in the browser console to add border to any answer posted by you and sort it to the top | |
function insertAfter(referenceNode, newNode) { | |
// reference: https://stackoverflow.com/a/4793630/6908282 | |
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling); | |
} | |
currUser = document.getElementsByClassName("s-user-card")[0]; | |
allAnswers = document.getElementsByClassName('answer'); | |
answersHeader = document.getElementById('answers-header'); | |
for (let answer of allAnswers ) { | |
userDetails = answer.querySelectorAll('.user-details'); | |
userHTML = userDetails[userDetails.length - 1]; | |
userAnchor = userHTML.children.item(0); | |
if (userAnchor.href == currUser.href){ | |
divToHighlight = answer; | |
insertAfter(answersHeader, divToHighlight); | |
divToHighlight.style.cssText = "padding: 5px;outline: 2px solid darkgreen;border-radius: 5px;" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment