SFGate with no comments: a Greasemonkey script

After a few months (sorry!) of downtime, my SFGate-NoComments Greasemonkey script is back up at Userscripts.

I realize the previous sentence makes very little sense to anyone but me, so I’ll expand it:

After a few months (sorry!) of downtime

You saw my to-do list(s), right?


The “comments” sections in SFGate (San Francisco Chronicle’s Web site) articles are disgusting, horrible, rude, homophobic (?!), racist and in every other way awful. I wanted a way to read stories on SFGate without even having to force myself not to look at the comments section.

Greasemonkey script

Greasemonkey is a mechanism by which arbitrary code can be injected into Web pages during load or after they are completely loaded. It’s available for almost every modern browser*. Some common uses for Greasemonkey scripts are adjusting font sizes and colors on pages where the Web developer apparently worked on a 30″ inch screen and has 20/10 uncorrected vision and the color sense of a three year old, removing page elements and otherwise enhancing usability of Web pages.


Userscripts.org is an online repository of thousands of user-submitted Greasemonkey scripts. I placed my script there when I first wrote it early this year.

How does it work, you ask? Pretty simple in concept, a real hair-tearer in execution. Using Greasemonkey scripts’ ability to access the structural elements of a Web page, and knowing (from examining the page source code) how comments sections are named and placed, my code goes through the DOM looking for specific items. When it finds them, it makes them disappear. This was made more difficult by the fact that SFGate is now using a third-party comments solution which loads after most of the rest of the page has already finished loading, so I had to make my code wait until the page, including comments, had fully loaded before executing. The result is that the comments links and sections do show for a second before disappearing, but I find that acceptable considering the outcome.

This was an interesting challenge for me and as usual, it was impossible until it became easy. I would be willing to look at extending or duplicating it for other sites with similarly offensive comments sections. Let me know in the comments below if you’re interested. Yes, I realize the irony.

*Greasemonkey for:

  • Safari/Mac: Greasekit** or NinjaKit. I haven’t tried NinjaKit yet.
  • Opera: Enable user scripts and point it to the directory where you’ve downloaded your scripts.
  • Chrome: Native support, just click “Install” from Userscripts pages.
  • IE: See links here. I haven’t tried any of these because I use IE only under extreme duress.

**Use this version of GreaseKit if you are on OS X Leopard. The current posted version was compiled for Snow Leopard.

Comments off

Block comments on SFGate.com

The “comments” section under every SFGate.com article is a cesspool (I’m not the first person to say this but I can’t immediately find where it was said first) filled with hate, bigotry, trolling and various evil. Sure, you don’t -have- to click through to the comments but SFGate helpfully shows the three highest-rated comments below each article–and the worst, and most prolific, commenters have hacking scripts that artificially inflate their comments’ ratings. Here’s another view on SFGate’s comment section: link.

Feeling that “out of sight, out of mind” is a good policy, my first UserScript hides several DIVs associated with comments on SFGate article pages. Here’s the source:

// ==UserScript==
// @name SFGate-NoComments
// @namespace http://www.userscripts.org
// @description Hide comments on SFGate.com articles
// @version 0.2
// @include http://www.sfgate.com/*
// @copyright 2010+, Andrew Rich (http://www.project-insomnia.com)
// @license (CC) Attribution Non-Commercial Share Alike; http://creativecommons.org/licenses/by-nc-sa/3.0/
// ==/UserScript==

var commentsDiv = document.getElementById('commentspage');
commentsDiv.style.display = 'none';
var commentslinksSpan = document.getElementById('commentslinks');
commentslinksSpan.style.display = 'none';
var commentBoxWrapperDiv = document.getElementById('articlePageCommentBoxWrapper');
commentBoxWrapperDiv.style.display = 'none';
var recCommentsDiv = document.getElementById('sfgate_recommended_comments');
recCommentsDiv.style.display = 'none';
var commentsListDiv = document.getElementById('commentslist');
commentsListDiv.style.display = 'none';
var commentsContainerDivAttrs = document.getElementById('Comments_Container_viewall').attributes;
commentsContainerDivAttrs.getNamedItem('class').value = '';
var commentsContainerDiv = document.getElementById('Comments_Container_viewall');
commentsContainerDiv.style.visibility = 'hidden';

I hope this is useful to you and thank you for reading. You can install it easily from the UserScripts.org link above. Tested in Safari 4.0.4 (5531.21.10) with GreaseKit 1.7 on Mac OS X 10.5.8 Build 9L30. Should work in other UserScript-supporting browsers (Firefox, Opera, Chrome “Dev Channel”) without issue.

Comments off