Skip to content

Instantly share code, notes, and snippets.

@noscript
Last active July 2, 2024 15:39
Show Gist options
  • Save noscript/b0420686256ab961e4e3f668bf9f1f5b to your computer and use it in GitHub Desktop.
Save noscript/b0420686256ab961e4e3f668bf9f1f5b to your computer and use it in GitHub Desktop.
Hacker News: New Comment Marker
// ==UserScript==
// @name Hacker News: New Comment Marker
// @description Make "new" comments since your last visit especially visible
// @downloadURL https://gist.github.com/noscript/b0420686256ab961e4e3f668bf9f1f5b/raw/hacker-news-new-comment-marker.user.js
// @namespace https://gist.github.com/noscript
// @grant GM_addStyle
// @grant GM_getValue
// @grant GM_setValue
// @version 3
// @include https://news.ycombinator.com/item?id=*
// ==/UserScript==
GM_addStyle('.unread { background: #FBFB78; }');
let postId = document.location.href.replace(/.*\?id=/, '');
let oldLatest = GM_getValue(postId, 0);
let newLatest = 0;
Array.from(document.querySelectorAll(".comhead .age")).forEach((el) => {
let timestamp = Date.parse(el.title);
if (oldLatest > 0 && timestamp > oldLatest) {
el.closest('table').classList.add('unread');
}
if (timestamp > newLatest) {
newLatest = timestamp;
}
});
GM_setValue(postId, newLatest);
@noscript
Copy link
Author

Screenshot:
screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment