Skip to content

Instantly share code, notes, and snippets.

@AnweshGangula
Last active June 29, 2022 14:31
Show Gist options
  • Save AnweshGangula/4fdcc804bcaa0636f4987e8b3a553953 to your computer and use it in GitHub Desktop.
Save AnweshGangula/4fdcc804bcaa0636f4987e8b3a553953 to your computer and use it in GitHub Desktop.
Highlight Current Users Answer in Stack overflow
// 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