Comment Snob

Comment Snob is an extension for Google Chrome that filters out undesirable comments from comment threads on the Web. You can install it here.

Before: After:

It comes with support for YouTube by default, but you can add support for many other sites by installing Comment Snob rules. For each rule that you install, you can choose from the following filtering parameters:

Installing Comment Snob Rules

There are two ways to install a comment snob rule:

  1. Click on a Comment Snob rule link in a webpage. A bar will appear at the top of your browser allowing you to install the rule. (Try clicking this link: Comment Snob Rule for Mashable)



  2. Or, open the Comment Snob options and write your own Comment Snob rule.


Featured Comment Snob Rules


Writing a Comment Snob Rule

Are you familiar with HTML and jQuery? Then you can write Comment Snob rules for any website you want.

Components of a Rule

A Comment Snob rule is a JSON object that tells Comment Snob how to find comments on a website and where to place the "Show/Hide" toggle for each comment. These are the properties that each rule should (or can) have; all selectors should be written for consumption by jQuery:

Attribute Required Description
idYesA string that should be unique to your rule. This is used to make sure that the same rule is not installed multiple times.
labelYesA string that describes your rule to a user. It will usually be the name of the website that it filters.
urlYesA regular expression (encoded in a string) that describes the URLs for which your rule should be run.
allCommentsSelectorYesA selector that selects the smallest possible container that contains all of the comments for the page.
commentContainerSelectorYesA selector that selects the largest possible container that contains only a single comment, using allCommentsSelector as a starting point.
commentTextSelectorOptionalA selector that selects the smallest possible container that contains all of the text for a comment, using commentContainerSelector. If not specified, defaults to commentContainerSelector.
commentHideSelectorOptionalA selector that selects any nodes that should be hidden when a comment is filtered, using commentContainerSelector as a starting point. If not specified, commentTextSelector will be used.
statusElementTagOptionalThe HTML tag name that should be used to hold the "Show/Hide" toggle and the reason for filtering. If not specified, defaults to "span".
statusContainerSelectorOptionalA selector that selects the element that will be used as a point of reference for where the "show/hide" toggle and filtering reason is placed for each comment. If not specified, defaults to commentContainerSelector.
statusPlacementOptionalOne of "prepend", "append", "before", or "after"; used along with statusContainerSelector to insert the filtering status into each filtered comment. Defaults to "prepend".
statusElementAttributesOptionalA hash containing name/value pairs for attributes that can be added to the placeholder element specified by statusElementTag.
ajaxInitiatorSelectorOptionalA selector that selects any UI elements that might be clicked to trigger loading more comments via AJAX, using allCommentsSelector as a starting point.
dynamicOptionalA boolean value (defaults to false) that indicates whether the website's comments are not included in the main pageload, but are immediately loaded after the page loads. Disqus is the most common example of this.
updateURLOptionalA URL where the JSON for this rule can be retrieved (for automatic updates).
authorOptionalYour name, email address, or website.
descriptionOptionalA text description of your rule, only recommended if the label doesn't fully describe the functionality.

The simplest possible rule might look like this:

{
	"id": "test@example.com",
	"label": "Example.com",
	"url": "^http://example\\.com/",
	"allCommentsSelector": "#comments",
	"commentContainerSelector": ".comment"
}

Rule Discovery

To let users install your rule, just link to a file containing only the JSON, and give the <a> tag a "comment-snob-rule" class:

<a href="http://www.chrisfinke.com/comment-snob/rules/hn.snob" class="comment-snob-rule">Comment Filter for Hacker News</a>

(You could also include the JSON in the href attribute directly as a data URI.)

Users can also install rules by opening a JSON file whose filename ends in ".snob" directly in the browser.

Questions?

E-mail me at cfinke@gmail.com.