🏠 Home 

HN highlight fresh comments

Highlights fresh comments on Hacker News.


Install this script?
  1. // ==UserScript==
  2. // @name HN highlight fresh comments
  3. // @description Highlights fresh comments on Hacker News.
  4. // @version 1
  5. // @namespace https://greasyfork.org/en/scripts/6955-hacker-fresh
  6. // @include http://news.ycombinator.com/*
  7. // @include https://news.ycombinator.com/*
  8. // @grant GM_addStyle
  9. // ==/UserScript==
  10. GM_addStyle(".fresh-item { background-color: #FEE67F; border-radius: 3px; }");
  11. (function() {
  12. 'use strict';
  13. function get_comment_id(vote_box) {
  14. var item_link_ele = vote_box.parentElement.querySelector('.comhead > a:nth-child(2)');
  15. // Check for deleted comment
  16. if (item_link_ele === null) {
  17. return null;
  18. }
  19. var link = new URL(item_link_ele.href);
  20. return link.searchParams.get('id');
  21. }
  22. var all_vote_box = document.querySelectorAll('tbody > tr > td[valign=top]');
  23. for (var e of all_vote_box) {
  24. e.classList.add("vote-box");
  25. var item_id = get_comment_id(e);
  26. if (item_id !== null) {
  27. var status = localStorage.getItem(item_id);
  28. if (status === null) {
  29. e.classList.add("fresh-item");
  30. localStorage.setItem(item_id, "seen");
  31. }
  32. }
  33. }
  34. })();