Mar 29, 2011

A Partial Solution for Facebook Inanity

Much better.
I was playing around with learning jQuery today and ended up writing a small Greasemonkey script for Facebook. Essentially what the script does is replace all of the comments displayed in the news feed on your home page with the first part of a random Wikipedia article and a link to the full article.

 Conveniently, comments on the front page of Facebook are the only things in <span> tags with a data-jsid="text" attributes which makes finding them very easy with jQuery. The script sends of a request using the GM_xmlhttpRequest function from the Greasemonkey API to http://en.wikipedia.org/wiki/Special:Random. Then once again jQuery can be used to easily find the the first <p> tag in the <div> with an id of bodyContent from the returned Wikipedia page. The resulting text can then replace that of the comment.

The code itself is rather hacked together at the moment. If I feel sufficiently motivated I will eventually extend it to be a little more complex as I get a better grasp of jQuery and javascript in general.

A note about compatibility: I only tested the script on my computer using Firefox. Chrome supports user scripts natively but to use this script you will need to install an extension like Tampermonkey or Ninjakit to allow GM_xmlhttpRequest to send cross domain requests and for the @require metadata statement. Ninjakit is the only option for Safari that I know of. As for the rest, Google will know better than I.

You can grab a copy of the script from here. Any feedback, from features to coding suggestions, would be awesome.

3 comments:

  1. This doesn't look like a post about evan's sex life.


    (nonetheless what made you think about doing this?)

    (also that's pretty awesome. Please use it for nefarious purposes on 4/1)

    ReplyDelete
  2. This. looks. awesome.

    ReplyDelete
  3. I actually had the idea and wrote a greasemonkey script a while ago that did the same thing except with status updates using just plain javascript. It eventually broke when Facebook changed stuff, as I'm sure this one will, and I didn't feel like trying to update it. Yesterday I was trying to think of a small project I could do to start learning a little jQuery and eventually thought of this. I did it with comments this time as there are generally more of them on the page.

    ReplyDelete