Show HN: Display a bell emoji on HN comments you haven't read yet(gist.github.com)
gist.github.com
Show HN: Display a bell emoji on HN comments you haven't read yet
https://gist.github.com/linkdd/76fd57d02480c3e36a4e3f8ce39322b1
98 comments
Next to your comment there's a timestamp for when it was posted, with the title "2021-09-15T14:18:16". This is available for all comments as far as I can see. In what way is this inaccurate?
I think I like the outlined approach (minus the rant) that GP described - it sounds kind of simple, yet elegant.
I actually ended up writing an HN backend for my comment highlight user script I described earlier, here’s the HN version: https://gist.github.com/justjanne/e61fcc9edb7d3dc60bc1a788d0...
That's neat! :)
Oh, that's nice! last time I developed a browser addon like that (half a decade ago, tbh) that didn’t exist yet.
Neat!
Neat!
But it would break the workflow of so many people relying on that shitty structure!
https://xkcd.com/1172/
I like the fact that HN is so "stable".
https://xkcd.com/1172/
I like the fact that HN is so "stable".
HN is so "table", I'd say.
Comment item ids are sequential (unless that’s changed since I last looked). You can perform relative ordering operations using them just like you could dates.
I actually ended up writing an HN backend for my comment highlight user script I described earlier, here’s the HN version: https://gist.github.com/justjanne/e61fcc9edb7d3dc60bc1a788d0...
this is really nice! i think i will learn jscript - i have no clue what i am getting into but thanks for inspiring
ps im a mechanical engineer
ps im a mechanical engineer
Nitpicking: Note that JScript[1] is not Javascript. The common abbreviation for Javascript is js.
[1] https://en.wikipedia.org/wiki/JScript
[1] https://en.wikipedia.org/wiki/JScript
Based on the most recent stable release being 2011, I agree. But I found it funny that the article also says "A lot of people think that JScript and JavaScript are different but similar languages. That's not the case. They are just different names for the same language"!
I was going to leave a comment complimenting you on your awesome HN username, but I try not to go off on too many tangents.
However, I notice you have exactly 1337 karma right now. So the combination of hunter2 + 1337 is too irresistible not to mention. :) https://i.imgur.com/PM1T8DM.jpg
(It's strange that http://bash.org/?244321 "only" has ~40k upvotes. I remember upvoting it when I was in high school, and it still seems to be working today, so you'd think a famous bash.org quote would accumulate more than a mildly popular Reddit post worth of upvotes...)
Anyway, have a great week!
However, I notice you have exactly 1337 karma right now. So the combination of hunter2 + 1337 is too irresistible not to mention. :) https://i.imgur.com/PM1T8DM.jpg
(It's strange that http://bash.org/?244321 "only" has ~40k upvotes. I remember upvoting it when I was in high school, and it still seems to be working today, so you'd think a famous bash.org quote would accumulate more than a mildly popular Reddit post worth of upvotes...)
Anyway, have a great week!
Ok let's get off-topic because it's not everyday someone posts about bash.org. My favorite:
http://bash.org/?835030
http://bash.org/?835030
Hahaa, I love that one.
I remember reading http://bash.org/?5273 as a teenager and thinking "What! How could anyone possibly lose a whole computer?" But then I lost a fully-working-responds-to-ping raspberry pi a few years ago too. :)
Cheers!
I remember reading http://bash.org/?5273 as a teenager and thinking "What! How could anyone possibly lose a whole computer?" But then I lost a fully-working-responds-to-ping raspberry pi a few years ago too. :)
Cheers!
Heh, thanks and you too!
Even from the day it was made it was never the same language it was however a superset of JavaScript (at the time) having several proprietary extensions to the language.
Nice, I'd really like one to collapse all second-level comments. There's enough 1000+ comment links now that the top comment takes up the entire page and everyone wandering in tends to just respond to that or the children rather than numerous others making valid points.
The extension “Refined Hacker News” for Chrome lets you click to collapse a comment thread.
This is now a feature of hacker news itself, as of a year or two ago (?). No extension required. I think the parent comment wants a feature to collapse all comment threads at the same time, so only the top level comments are visible.
Can you elaborate? The feature seems nice, but I access HN on multiple browsers for which a plugin isn't workable.
Looking at settings and links on the page I don't see any functionality like you describe.
Looking at settings and links on the page I don't see any functionality like you describe.
Click on [–] at the end of a comment header with JavaScript enabled.
Ah, that’s right. (It’s the [-] link in the comment header.) RFN does have a link at the top of the story page called "toggle all commments," but I guess it’s broken, as it only seems to toggle the first comment. The extension does have a convenient feature, a [collapse root] link on each comment in a thread, so you can collapse the thread from within it, without having to find its origin.
Hi! Creater of Refined Hacker New here :).
You mentioned that the "toggle all comments" button is broken, could you elaborate a bit more on that, and if possible open a GitHub issue for it? Thanks a lot :D.
Apart from that, with RHN you can navigate through the comments using the "J" and "K" keyboard keys and Press "Enter" on the highlighted comment to toggle it. Hope that helps too, cheers :)
You mentioned that the "toggle all comments" button is broken, could you elaborate a bit more on that, and if possible open a GitHub issue for it? Thanks a lot :D.
Apart from that, with RHN you can navigate through the comments using the "J" and "K" keyboard keys and Press "Enter" on the highlighted comment to toggle it. Hope that helps too, cheers :)
Thanks for the great extension, it makes reading HN more...refined.
Well, I tried the [toggle all comments] button on a couple of stories before posting my comment, and it was only toggling the first comment. But I did more testing for this reply, and now it’s working as advertised. I can’t explain that, but if I every figure out the conditions that prevent it from working, I’ll open an issue.
Well, I tried the [toggle all comments] button on a couple of stories before posting my comment, and it was only toggling the first comment. But I did more testing for this reply, and now it’s working as advertised. I can’t explain that, but if I every figure out the conditions that prevent it from working, I’ll open an issue.
Alright, glad it's working now! And thanks for the kind words, appreciate it.
[deleted]
This should do the trick:
[ ...document.querySelectorAll('td.ind[indent="1"] + td.votelinks + td.default .comhead > .togg') ].forEach(div => div.click())https://hackerweb.app/ does this for items with a lot of comments.
HN should copy this feature. The top thread dominates the discussion all too often.
HN should copy this feature. The top thread dominates the discussion all too often.
Not the same, but similar? I sometimes use this bookmarklet to jump to the next root thread:
javascript:if (typeof hn_next_comment_to_jump_to == 'undefined') { pkqcbcnll = 0 }; document.querySelectorAll("img[src='s.gif'][width='0']")[hn_next_comment_to_jump_to++].scrollIntoView(true);There was a typo (pkqcbcnll should've been hn_next_comment_to_jump_to). Here's a fixed version:
javascript:if (typeof hn_next_comment_to_jump_to == 'undefined') { hn_next_comment_to_jump_to = 0 }; document.querySelectorAll("img[src='s.gif'][width='0']")[hn_next_comment_to_jump_to++].scrollIntoView(true);
Thanks for this!Adding the following lines to the script posted by OP should add buttons for doing just that:
var collapseButton = document.createElement("button")
collapseButton.textContent = "Collapse level 2 comments"
collapseButton.onclick = (event) => document
.querySelectorAll('td[indent="1"]+td+td.default .togg')
.forEach((button) => {
if (button.textContent == "[–]") {
button.click()
}
})
var expandButton = document.createElement("button")
expandButton.textContent = "Expand level 2 comments"
expandButton.onclick = (event) => document
.querySelectorAll('td[indent="1"]+td+td.default .togg')
.forEach((button) => {
if (button.textContent != "[–]") {
button.click()
}
})
var table = document.querySelector("table.comment-tree")
table.parentNode.insertBefore(collapseButton, table)
table.parentNode.insertBefore(expandButton, table)Nice short implementation.
Here's a similar userscript I use: https://greasyfork.org/en/scripts/18066-hn-comment-trees/
Here's a similar userscript I use: https://greasyfork.org/en/scripts/18066-hn-comment-trees/
Better than just upvoting everything, which is how I track this now.
You've made me realise I do something similar. It's probably a good idea that you're forbidden from downvoting direct replies though, because that's often a temptation.
This is so useful! I've previously resorted to searching the page for the word "minutes" to see the recent comments, but that's been unsatisfying.
I only wish that we didn't have to use third party extensions for loading scripts like this. I can never quite bring myself to trust them with full access to all of my pages. This really should be a part of the browser functionality already.
I only wish that we didn't have to use third party extensions for loading scripts like this. I can never quite bring myself to trust them with full access to all of my pages. This really should be a part of the browser functionality already.
The extension I listed stores your scripts in localStorage.
But I agree, it should be a browser feature.
But I agree, it should be a browser feature.
What if we could add our own JavaScript within our user settings on HN?
That would be a new feature. The philosophy of HN is to evolve slowly and carefully.
This surely would break someone's workflow ;)
https://xkcd.com/1172/
This surely would break someone's workflow ;)
https://xkcd.com/1172/
Not break anything, just option “hidden” under settings. Just as they open the possibility to add HEX value to change the color on HN when you reach enough points on HN
HN would need to store the scripts and load them. This would mean slower loading time, and increased maintenance on databases.
Also open the door to bugs like "why is this loading the scripts of another user?" which can be security threats.
It's "just" a simple feature, but it still have costs. I'd rather have the browser allowing me to load scripts without relying on an extension.
Also open the door to bugs like "why is this loading the scripts of another user?" which can be security threats.
It's "just" a simple feature, but it still have costs. I'd rather have the browser allowing me to load scripts without relying on an extension.
On the other hand, it is kind of weird that a site called "Hacker News" is less hackable than MySpace back in the day. At the very least they could redesign the layout to make it easier for external scripts to deal with.
Given how many people here long for the quirky old days of the web, I say whomever starts a thread should also get to create a custom CSS theme for it.
Given how many people here long for the quirky old days of the web, I say whomever starts a thread should also get to create a custom CSS theme for it.
This is a sweet and simple implementation, however I don't think the title "[...] you haven't read yet" is correct. The code caches every comment ID which exists in the page, even ones outside of the viewport. A more accurate title would be "Display a bell emoji on new HN comments".
- Using the JavaScript Intersection Observer may be an interesting addition, as this would explicitly differentiate comments on the thread which you may not have scrolled down to.
- Using the JavaScript Intersection Observer may be an interesting addition, as this would explicitly differentiate comments on the thread which you may not have scrolled down to.
[deleted]
> This is a sweet and simple implementation
I love one-thing-well items of code instead of large (and thus non-secure) abstractions built upon other abstractions. Big fan of the K.I.S.S principle https://en.wikipedia.org/wiki/KISS_principle
I love one-thing-well items of code instead of large (and thus non-secure) abstractions built upon other abstractions. Big fan of the K.I.S.S principle https://en.wikipedia.org/wiki/KISS_principle
I will point out that that reason this can be so concise is because of a set of large foundational abstractions.
Good point. I never thought of it that way. The modern PC is a marvel. On one hand it's a complex mess, on the other we can write poetry like that JS snippet, and it all works seamlessly (unless you're doing something weird).
I changed the script so that the bells stay till you mouseover each HN comment: https://news.ycombinator.com/item?id=28540049
I've made userscript that locally stores hashes of titles and comments that stays in viewport for some time period and adds some marker to those displayed for the first time (i.e. guaranteed to be "unread" for the browser profile, provided there was no edit).
https://greasyfork.org/en/scripts/423969-hn-style-unread-con...
It uses IntersectionObserver for "exposition watch" and "crypto.subtle.digest" for SHA-1 hashes - I was pleasantly surprised those native APIs are enough to get this magic working.
It's very POC-ey (absolutely no checks for storage capacity etc) but works quite well for me.
E: Actual markers are just light green right borders on "unread" items that slightly fades out after "exposition timeout". I'm using dark userstyle for HN (https://uso.kkx.one/style/71155 ); in default theme they are probably too light to be visible.
https://greasyfork.org/en/scripts/423969-hn-style-unread-con...
It uses IntersectionObserver for "exposition watch" and "crypto.subtle.digest" for SHA-1 hashes - I was pleasantly surprised those native APIs are enough to get this magic working.
It's very POC-ey (absolutely no checks for storage capacity etc) but works quite well for me.
E: Actual markers are just light green right borders on "unread" items that slightly fades out after "exposition timeout". I'm using dark userstyle for HN (https://uso.kkx.one/style/71155 ); in default theme they are probably too light to be visible.
[deleted]
Wouldn't it make more sense to add an "unread" class to the comment and style it with css instead of appending new elements?
I also think it would make sense to store the page load time, and compare to a comment's post time to determine if it's new instead of storing all comment ids.
I also think it would make sense to store the page load time, and compare to a comment's post time to determine if it's new instead of storing all comment ids.
I already have a custom CSS (using Stylus) for Dark Mode.
The CSS is trickier due to the HTML structure.
The CSS is trickier due to the HTML structure.
I was thinking of something like this:
Edit: I used the actual bell emoji in the code, but HN removed that, so I just replaced it with :bell:.
let style = document.createElement('style');
style.innerHTML = ".unread::after {content: ':bell:'}";
document.getElementsByTagName('head')[0].appendChild(style);
document.querySelectorAll('.athing.comtr').forEach(comm => {
if (comment is unread) {
comm.querySelector('.comhead').classList.add("unread");
}
})
That shouldn't collide with other custom CSS, and it avoids adding extra elements in the loop.Edit: I used the actual bell emoji in the code, but HN removed that, so I just replaced it with :bell:.
While we are here, let me plug my chrome extension that tracks comments which have been read https://github.com/kklisura/hn-comment-tracker
The read comments have striped background and orange bar on the right, so identifying unread is easy.
The read comments have striped background and orange bar on the right, so identifying unread is easy.
I use a FireFox plugin that applies CSS for colorizing visited links on HN:
a:link{
color: orange !important;
}
/* visited link */
a:visited {
color: green !important;
}
https://mybrowseraddon.com/custom-style-script.htmlthey are already distinguishable by color without any change. this is about comments although it marks only comments as new it hasn't seen before regardless if you read them or not.
This gave me the idea that I would like that standard everywhere. This convention is just so helpful. Maybe replacing with an outline on more heavily styled links, so as not to break layouts too much.
Is it not the standard everywhere? All my links, on every page, are lighter when visited. I suppose some sites might override this, but I've rarely seen it.
It is standard everywhere unless a site explicitly overrides it.
For example, do a Google search and click one of the links. Now do the same search again. The link you followed last time is now purple instead of blue. On Hacker News the links go a lighter grey.
For example, do a Google search and click one of the links. Now do the same search again. The link you followed last time is now purple instead of blue. On Hacker News the links go a lighter grey.
Yes I know, but a lot of websites override it, I'd just like a unified style everywhere. To be honest I'd like consistent styling in a lot more places and I know of some add-ons that get pretty close but not quite.
Sorry, yeah, so you meant it'd be nice to have a feature/add-on that overrides the link colouring to be the same on every site. Absolutely. We had that once, in those distant days before CSS...
----
Edit:
This works on Firefox:
- Install Stylus[0].
- Click the toolbar icon and choose Manage.
- Click "Write new style"
- Enter and save this:
----
Edit 2:
In Firefox WITHOUT installing any add-ons:
- Go to about:config
- Set toolkit.legacyUserProfileCustomizations.stylesheets to true
- Press Alt, click Help -> More Troubleshooting Information
- Next to "Profile Folder", click Open Folder
- Create a new folder there called "chrome"
- Make a file in that folder called userContent.css
- Enter the following CSS:
----
Edit:
This works on Firefox:
- Install Stylus[0].
- Click the toolbar icon and choose Manage.
- Click "Write new style"
- Enter and save this:
a:link {
color: #0000EE;
}
a:visited {
color: #551A8B;
}
[0] https://addons.mozilla.org/en-US/firefox/addon/styl-us/----
Edit 2:
In Firefox WITHOUT installing any add-ons:
- Go to about:config
- Set toolkit.legacyUserProfileCustomizations.stylesheets to true
- Press Alt, click Help -> More Troubleshooting Information
- Next to "Profile Folder", click Open Folder
- Create a new folder there called "chrome"
- Make a file in that folder called userContent.css
- Enter the following CSS:
a:link {
color: #0000EE !important;
}
a:visited {
color: #551A8B !important;
}
- Restart FirefoxTurns out you can do what the top comment by chhickman is doing without any addon as well. Follow my steps above in "Edit 2", and add this to your CSS file:
@-moz-document domain(news.ycombinator.com) {
a:link {
color: orange !important;
}
/* visited link */
a:visited {
color: green !important;
}
}
Per-domain custom CSS supported out of the box!HN does not aim to be infinite scroll social media which addicts you and makes you keep checking and re-checking for more obsessively. It is purposefully barebones so that you're not tempted to read every single comment and waste time.
> makes you keep checking and re-checking for more obsessively.
Yet I do this more on HN than any other site since I don't know if someone's responded to me.
Noprocrast was... helpful, I guess, but I found myself racing to make poor quality responses sometimes, or HN was constantly locked out whenever I wanted to take a short break, instead of being able to take the time to respond with a thoughtful answer.
Yet I do this more on HN than any other site since I don't know if someone's responded to me.
Noprocrast was... helpful, I guess, but I found myself racing to make poor quality responses sometimes, or HN was constantly locked out whenever I wanted to take a short break, instead of being able to take the time to respond with a thoughtful answer.
You can get notified of replies via email: https://www.hnreplies.com/
Responses aren't necessarily "to you"
If you are going to post a comment that does nothing more than respond to the previous person, you are doing a disservice by forcing thousands of people to read text that is likely irrelevant or unhelpful to them.
The fact that this site is designed to prevent this behavior is one of its stronger points IMHO
If you are going to post a comment that does nothing more than respond to the previous person, you are doing a disservice by forcing thousands of people to read text that is likely irrelevant or unhelpful to them.
The fact that this site is designed to prevent this behavior is one of its stronger points IMHO
You've completely missed the point of why I want response notifications.
I get where you're coming from, but unless you're the only expert in your field, I think it's better to have group discussions.
Response notifications will primarily be used by people to dominate the chat, and your use case doesn't negate that.
Response notifications will primarily be used by people to dominate the chat, and your use case doesn't negate that.
I think you're accusing me a of a lot of personality traits I do not possess. Why am I not allowed to respond to people if I so choose? There isn't a limited amount of allowed responses.
you're allowed to respond to whomever you can. the explicit design goal is to avoid comments that are noise on a web forum, even if they're expected in normal conversation. reply comments like "thanks for the link!" (whether you do that or not) are seen to not add that much value, and so are discouraged
So, I get and appreciate the lack of notifications and distractions on HN.
That said, I'd really like a way to find, distraction free(so in some submenu), reply comments.
The current way seems narcissistic, as I have to go through my whole history to see why may have replied. And even then I have to do math to figure out if I'd seen it or not.
That said, I'd really like a way to find, distraction free(so in some submenu), reply comments.
The current way seems narcissistic, as I have to go through my whole history to see why may have replied. And even then I have to do math to figure out if I'd seen it or not.
I use https://www.hnreplies.com/ for that
Thanks! I was hoping for something on the site, as I don't really want to be 'notified'. That said, I just plugged in an email I don't check often so that should accomplish it about the same. Never knew this existed - thanks again.
Hacker News: The only place on the net where you actually should read the comments.
Another chrome extension that does similar things https://chrome.google.com/webstore/detail/hckr-news/mnlaodle...
+ my userscript https://github.com/raszpl/hackahackernews
I'm not sure if this is something I am fine to say, but I've never signed an NDA or something so I'll just say: (Moderators, feel free to hide this comment if you would rather not like an influx of alpha testers.)
If you sign up to the alpha-testing HN[0], you get access to the thread feature, which is... (quoted from my forwarded mail)
> New feature: when you visit a thread, the software now highlights
> comments that are new since you last viewed the page. These are
> displayed with an orange (or whatever your topcolor is) bar to the
> left of the new comment. Refreshing the page will reset these.
Very useful, I can't imagine having HN without these indicators any more.
[0]: https://news.ycombinator.com/item?id=22788678
If you sign up to the alpha-testing HN[0], you get access to the thread feature, which is... (quoted from my forwarded mail)
> New feature: when you visit a thread, the software now highlights
> comments that are new since you last viewed the page. These are
> displayed with an orange (or whatever your topcolor is) bar to the
> left of the new comment. Refreshing the page will reset these.
Very useful, I can't imagine having HN without these indicators any more.
[0]: https://news.ycombinator.com/item?id=22788678
I wrote a userscript that implements exactly that, but with the added benefit of storing every time you visited that page, so you can select between all your visits to that page and see which comments have been added after each visit. https://gist.github.com/justjanne/e61fcc9edb7d3dc60bc1a788d0...
For those who don't want to switch to alpha, I made a bookmarklet that lets you enter an amount of time and highlights comments made within that amount of time (i.e. "15 minutes" ago, etc)
https://news.ycombinator.com/item?id=25424560
https://news.ycombinator.com/item?id=25424560
How do you sign up for it?
Taken from the parent comment : https://news.ycombinator.com/item?id=22788678
I used to be on the beta testing list, but I think I was removed.
It would be nice if awareness of this was more visible, maybe as a link on the footer, with a list of in progress or planned features.
It would be nice if awareness of this was more visible, maybe as a link on the footer, with a list of in progress or planned features.
I updated the script so that bells stay until you click on each HN comment you read: https://gist.github.com/shawwn/d0c370212793eeefdf6ef50468afe...
Surprisingly it doesn't annoy me, because I'm often clicking on the comments I read anyway. (Old habit.)
EDIT: I changed it to onmousemove. Feels pretty nice!
Surprisingly it doesn't annoy me, because I'm often clicking on the comments I read anyway. (Old habit.)
EDIT: I changed it to onmousemove. Feels pretty nice!
Awesome, thank you!
(Fixed a typo; if you were getting an error, try now. Sorry about that!)
Is there a "diff" type addon for all web pages? That would be so helpful. To be clear, I'd like a diff against stuff that I actually could've read (that's been in the viewport) not simply loaded.
Nice I added on the below as the Windows emoji is a bit big for my liking and keeps the emoji color neutral.
span.style.cssText = `
font-size: 5px;
color: transparent;
text-shadow: 0 0 0 gray;
margin-bottom: 2px;
vertical-align: middle;
display: inline-block;
`Additionally, I'm a big fan of the Hacker News Notifications extension[0] to keep track of responses to my conversations.
It adds a small bell icon with a dropdown to the navbar that shows new replies to your posts and comments. 10/10, would recommend.
[0]: https://chrome.google.com/webstore/detail/hacker-news-notifi...
It adds a small bell icon with a dropdown to the navbar that shows new replies to your posts and comments. 10/10, would recommend.
[0]: https://chrome.google.com/webstore/detail/hacker-news-notifi...
Dumb question... so how do I actually use this?
There is no such thing as a dumb question.
There is a Chrome extension "Custom Javascript for Website" (link in the first line of the snippet) that lets you add JS scripts to any website.
Install the extension, then while on hackernews, open the extension and copy-paste the snippet into it.
There is a Chrome extension "Custom Javascript for Website" (link in the first line of the snippet) that lets you add JS scripts to any website.
Install the extension, then while on hackernews, open the extension and copy-paste the snippet into it.
Thank you for the assistance. So do I have to repeat the copy-paste each time I open HN? Also, it didn't work for me the first time, or now.
[deleted]
this add a slider selector for the time range to consider
and give higher values of alpha channel to more recent posts.
const div = document.createElement("div");
div.innerHTML = `<div style="position:fixed;top:20px;right:20px;width:40px;background:#ff05;">
<input type="range" orient="vertical" id="interval" min="0" max="95" value="30" style="width:100%">
<label for="interval" style="display:block"></label>
</div>`;
const input = div.firstElementChild.firstElementChild;
const label = input.nextElementSibling;
document.body.appendChild(div);
const formatTime = (mins) => {
if (mins > 60) {
return `${Math.floor(mins / 60)}h ${mins % 60}m`;
}
return `${mins}m`;
};
const extrapolate = (val) => {
val = val * 2;
for (let t = 30; t <= 150; t += 30) {
val += Math.max(0, val - t);
}
return val;
};
input.oninput = () => colorStuff(extrapolate(input.value));
const colorStuff = (interval_minutes) => {
label.innerText = `${formatTime(interval_minutes)}`;
const comments = Array.from(document.getElementsByClassName("athing comtr"));
dates = Array.from(document.getElementsByClassName('age'));
dates.sort((c1, c2) => Date.parse((c2).title) - Date.parse((c1).title));
const now = new Date();
const timestamp = now.getTime() + now.getTimezoneOffset() * 60E3;
comments.forEach((c) => {
const commentDateString = c.getElementsByClassName("age")[0].title;
const diff=(timestamp-Date.parse(c.getElementsByClassName('age')[0].title))/60E3;
const diff2=(Date.parse(dates[0].title)-Date.parse(c.getElementsByClassName('age')[0].title))/60E3;
if (diff < interval_minutes) {
const alpha = (1 - diff2 / interval_minutes)**6;
c.style.backgroundColor = `rgba(100, 255, 100, ${alpha})`;
} else {
c.style.backgroundColor = "rgba(255, 255, 255,0)";
}
});
};
colorStuff(extrapolate(input.value));This discussion calls to mind the quote, miss-attributed to Albert Einstein, "We cannot solve our problems with the same thinking we used when we created them."
Linked snipped will overflow localstorage in ~year of daily use and might take hundreds of miliseconds to parse multi megabyte json on every page load. I do this in my version to prune:
function checkquota(){
// localStorage limit is ~5MB, should probably do something about exceeding quota ;)
// lets trigger around 3MB
// deleting half of the oldest empty(seen, never interacted with) entries first
// popping a warning when we finally reach over 2MB non empty
//
// total entries: localStorage.length
// storage bytes left: 1024 * 1024 * 5 - escape(encodeURIComponent(JSON.stringify(localStorage))).length
// non empty entries: Object.entries(localStorage).filter(value => value[1] != "1")
// non empty entries size: escape(encodeURIComponent(JSON.stringify(Object.entries(localStorage).filter(value => value[1] != "1")))).length
// empty entries sorted, oldest first Object.entries(localStorage).filter(value => value[1] == "1").sort(function (a, b) {return parseInt(a[0]) - parseInt(b[0]);});
//size check is expensive, can be as long as 500ms for full localstorage, limit size checks to ~once per 24h
if (GM_getValue("lastquotacheck") > Date.now()) return;
GM_setValue("lastquotacheck", Date.now()+86400000);
let size = encodeURIComponent(JSON.stringify(localStorage)).length;
console.log("Current size: "+size+" bytes");
if (size > 1024 * 1024 * 3)
{
alert("Current hackahackernews consumed localStorage size: "+size+" bytes, cleaning older entries to make more room.");
let sortedStorage = Object.entries(localStorage).filter(value => value[1] == "1").sort(function (a, b) {return parseInt(a[0]) - parseInt(b[0]);});
let cutout = parseInt(sortedStorage.length/2);
for (let [index, value] of sortedStorage.entries())
{
if (index < cutout)
{
localStorage.removeItem(value[0]);
}
}
size = encodeURIComponent(JSON.stringify(localStorage)).length;
console.log("Size after culling empty entries: "+size+" bytes");
let nonempty = Object.entries(localStorage).filter(value => value[1] != "1");
if (encodeURIComponent(JSON.stringify(nonempty)).length > 1024 * 1024 * 2)
{
console.log("Non empty entries size is over 2MB! currently at: "+encodeURIComponent(JSON.stringify(nonempty)).length+" bytes.");
if (confirm("Saved visited links are consuming "+encodeURIComponent(JSON.stringify(nonempty)).length+" bytes, delete half of the oldest entries?"))
{
let sortedNonempty = nonempty.sort(function (a, b) {return parseInt(a[0]) - parseInt(b[0]);});
let cutout = parseInt(sortedNonempty.length/2);
for (let [index, value] of sortedNonempty.entries())
{
if (index < cutout)
{
localStorage.removeItem(value[0]);
}
}
}
}
size = encodeURIComponent(JSON.stringify(localStorage)).length;
console.log("Final size after culling: "+size+" bytes");
}
}
That way the script only has to store the timestamps on which you visit a comment section, not the comment ids.
Additionally, that way you can select "highlight all comments since visit [...]" with a dropdown from which you can choose out of all recent visits you did.
Sadly, Hacker News does not provide any such metadata in the markup. (Just like the comment formatting is shit, and the markup structure is as well. HN should just copy the nesting markup and formatting 1:1 from reddit, and it'd be massively improved already).