-
-
Save shawwn/d0c370212793eeefdf6ef50468afe2da to your computer and use it in GitHub Desktop.
Add a bell emoji to unread comments on HackerNews
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
// 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