View and install the saidit Greasemonkey script on userscripts.org. Click here »

The saidit script enhances reddit comment pages by highlighting unread comments. It works by keeping track of the comments you’ve already viewed. Here’s what it looks like:

saidit

Features

  • Highlights unread reddit comments
  • Read comments are stored locally
  • Automatic removal of old data
  • Efficient implementation

Installation

If you’d like to give it a spin, make sure you have Greasemonkey installed. Then, just install saidit from userscripts.org. Have fun!

How it works

For every comment viewed on reddit, saidit records the comment id in a “seen comments list” using DOM Storage. When a reddit comments page is loaded, saidit scans through each comment and checks if the id is in the list. If the id is not found, the class “unread”, is added to the comment div (this class can then be styled to emphasize unread comments). The seen comments list is then updated to include the new comments.

Since the script scans through hundreds of comments during the time-sensitive page loading process, I needed to make checking comment ids as fast as possible. Experimentation showed that if the seen comment ids were loaded into the fields of an Object, looking up ids was much faster than using an Array. Currently, saidit takes up to 2.5 seconds on the largest comment pages (200+) on my machine. I’m continuing to look into ways of making it faster.

Interoperability

An interesting side-effect of using DOM Storage is that read comment data is accessible to JavaScript on reddit and any other user scripts. If you can think of any clever ways to use this data, feel free to load it using the loading code below, or simply fork saidit to create a new script. Please use your new powers for good, not evil!

Here’s what the data loading code looks like, using Mozilla’s non-standard implementation of DOM Storage:

var redditStorage = globalStorage.namedItem("www.reddit.com");
var pageThingID = getThingID(getPageThing());
var seenArray = [];
var seenObject = {};
 
var seenData = redditStorage.getItem("seen-"+pageThingID);
seenArray = seenData.value.split(",");
 
// Build an object for faster access
seenArray.forEach(function(element) {
  seenObject[element] = true;
});

The “unread” class can be styled in subreddit CSS to achieve different effects. Just use a CSS rule similar to the default (perhaps with !important added):

.comment.unread .tagline {
  font-weight: bold;
  background-color: #fea;
  display: inline;
}

If you discover any interesting ways to use these, please leave a comment!