• Posts
  • RSS
  • ◂◂RSS
  • Contact

  • Mark New Comments

    August 31st, 2014
    comments, tech  [html]
    Online discussion spaces tend to use either linear or threaded comments. With linear comments there's just one long series of responses while with threads each comment is attached to the one it's replying to. In general I really like threads: the clarity they give you is very powerful, allowing a large number of people to have a coherent discussion by all breaking off into their own overlapping mini-discussions around individual posts. A downside to threads, however, is it's very hard to come back to a discussion and see what's changed. If you just have a linear discussion you find the last comment you remember and read from there, but with threads you're kind of lost.

    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.

    While you could do this sort of thing with local storage, I wanted this to work on as many browsers as possible, so I used cookies. The key bit of javascript is this:

    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.

    Now you have some javascript that does:

    var comment_is_new = last_visit.length > 0 &&
                         comment_epoch_ts > last_visit/1000;
    
    And you mark up the comments based on comment_is_new.

    Comment via: google plus, facebook

    Recent posts on blogs I like:

    Who Should Bear the Risk in Infrastructure Projects?

    The answer to the question is the public sector, always. It’s okay to have private-sector involvement in construction, but the risk must be borne by the public sector, or else the private sector will just want more money to compensate for the extra risk. …

    via Pedestrian Observations November 30, 2020

    Fireside Friday, November 27, 2020

    Hey folks! Fireside this week. A bit of a change-up in terms of the coming attractions. I had planned to start “Textiles, How Did They Make It?” next, but I want to do a bit more reading on some of the initial stages of textile production (that is, the pr…

    via A Collection of Unmitigated Pedantry November 27, 2020

    Thoughts you mightn't have thunk about remote meetings

    Welcome to this week's edition of "building a startup in 2020," in which all your meetings are suddenly remote, and you probably weren't prepared for it. I know I wasn't. We started a "fully remote" company back in 2019, but …

    via apenwarr November 23, 2020

    more     (via openring)


  • Posts
  • RSS
  • ◂◂RSS
  • Contact