Last active
July 2, 2024 15:39
-
-
Save noscript/b0420686256ab961e4e3f668bf9f1f5b to your computer and use it in GitHub Desktop.
Hacker News: New Comment Marker
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
// ==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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot: