Hacker News Author Highlight

Makes the author name more apparent when scrolling through comments.

  1. // ==UserScript==
  2. // @name Hacker News Author Highlight
  3. // @namespace http://cantcode.com
  4. // @description Makes the author name more apparent when scrolling through comments.
  5. // @include https://news.ycombinator.com/item?id=*
  6. // @include http://news.ycombinator.com/item?id=*
  7. // @version 1.5
  8. // @grant none
  9. // @run-at document-idle
  10. // ==/UserScript==
  11.  
  12. // Colors
  13. const colors = {
  14. bg: "#8000FF",
  15. fg: "#fff",
  16. newUserFg: "#00FF00",
  17. }
  18.  
  19. // Author
  20. const subtextLinks = document
  21. .querySelector("table .subtext")
  22. .getElementsByTagName("a");
  23. const author = subtextLinks[0].textContent;
  24.  
  25. // Author Comments
  26. const commentAuthors = document.querySelectorAll(
  27. '.comhead a[href="user?id=' + author + '"]',
  28. );
  29.  
  30. const updateAuthor = (authorElement) => {
  31. authorElement.style.backgroundColor = colors.bg;
  32. authorElement.style.color = colors.fg;
  33. authorElement.style.padding = "1px 2px";
  34. authorElement.style.borderRadius = "3px";
  35.  
  36. // Override HN's embedded <font> for new users
  37. if (authorElement.innerHTML.includes('color=')) {
  38. authorElement.style.color = colors.newUserFg;
  39. authorElement.innerText = author;
  40. }
  41. };
  42.  
  43. commentAuthors.forEach(updateAuthor);