Skip to content

Instantly share code, notes, and snippets.

@shawwn
Forked from linkdd/hackernews-new-comms.js
Last active September 24, 2021 22:19
Show Gist options
  • Save shawwn/d0c370212793eeefdf6ef50468afe2da to your computer and use it in GitHub Desktop.
Save shawwn/d0c370212793eeefdf6ef50468afe2da to your computer and use it in GitHub Desktop.
Add a bell emoji to unread comments on HackerNews
// Can be used with https://github.com/xcv58/Custom-JavaScript-for-Websites-2
// This snippet is released under the terms of the CC0 license: https://creativecommons.org/publicdomain/zero/1.0/deed.en
// Updated by sillysaurusx (v0.1.0):
// - bells stay till you mouseover each HN comment
// - use a constant localStorage key
// future plans:
// - don't bell your own comments
// - a button to un-bell the current page (or comment subtree)
const url = "HN note comments";
const cache = JSON.parse(localStorage.getItem(url) || '{}')
document.querySelectorAll('.athing.comtr').forEach(comm => {
if (!cache[comm.id]) {
const span = document.createElement('span');
span.innerHTML = '🔔' // :bell: emoji
span.onmousemove = comm.onmousemove = e => {
console.log('noted ' + comm.id);
span.remove();
comm.onmousemove = null;
cache[comm.id] = Date.now();
localStorage.setItem(url, JSON.stringify(cache));
}
comm.querySelector('.comhead').append(span);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment