|August 31st, 2014|
|tech, comments [html]|
One solution is for the page to keep track of when you last visited, and highlight any comments that have been posted since then. I first saw this on lesswrong, more recently it's been added to slate star codex, and now I've added it to the comments here:
See how there's a little black line to the left of Alex's comment? That means it was posted more recently than the last time I visited the page.
Warning: boring technical details follow.
var last_visit = document.cookie.replace( /(?:(?:^|.*;\s*)jtk_last_visit\s*\=\s*([^;]*).*$)|^.*$/, "$1"); var current_time = new Date().getTime(); var one_year_gmt_str = new Date(current_time + 31536000000).toGMTString(); document.cookie = "jtk_last_visit=" + current_time + "; path=" + window.location.pathname + "; expires=" + one_year_gmt_str;What does this do? The first line reads the cookie jtk_last_visit if the browser sent it. If no value was sent it will just be "". (The crazy regex comes from an MDN post.) The next three lines set the jtk_last_visit cookie to the current time, make it expire one year later, and restrict the path to be for this page only. That's important: otherwise visiting any page on the site would clear your highlighted comments.
var comment_is_new = last_visit.length > 0 && comment_epoch_ts > last_visit/1000;And you mark up the comments based on