June 27, 2007

My first grease monkey script [citation needed]

For those of you that have looked up/browsed/etc. anything on Wikipedia lately, you've probably noticed the "citation Nazis"--I hate citation Nazis (movie?)--have taken over. There are some pages that have the "[citation needed]" tag on almost every sentence. With that in mind, I wrote my first Greasemonkey script this morning.

With the power of Greasemonkey (Firefoxonly), you no longer have to be annoyed by all of the clutter. The tags are completely removed from the page. First install Greasemonkey, and then click the link below to install the script. The source and an explanation are in the extended entry.

Download script

Here's the source of the script if you are interested:

// ==UserScript==
// @name            No Wikipedia Citation Needed
// @namespace       http://marcolson.net
// @description     Gets rid of [citation needed] in wikipedia
// @include         http://*.wikipedia.org/wiki/*
// ==/UserScript==

var anodes, node, supnode, parentnode;

anodes = document.evaluate("//a[@title='Wikipedia:Citing sources']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < anodes.snapshotLength; i++) {
node = anodes.snapshotItem(i);
supnode = node.parentNode;
parentnode = supnode.parentNode;
parentnode.removeChild(supnode);
}

document.normalize();


Basically, we do 3 things:


  1. Get a list of all of the nodes that have a citation title
  2. Traverse that list and remove the parents (the superscript node) from the document
  3. "Normalize" the document to combine the fragmented text nodes

The first step is to get a list of all of the anchor nodes that contain a "Citation Needed" tag. If we look at the source of the page, we notice that they all have a common title ("Wikipedia:Citing sources") so we look for all anchor nodes with that title with our nifty xpath expression: //a[@title='Wikipedia:Citing sources']

anodes = document.evaluate("//a[@title='Wikipedia:Citing sources']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

The next step is to traverse that list, get the parent of the parent. The firefox dom works in such a way that to remove a node, you need to know the parent and do a removeChild() operation. We also don't want to leave the superscript node in place, so that's why we get the parent of the parent--it's cleaner this way.

for (var i = 0; i < anodes.snapshotLength; i++) {
    node = anodes.snapshotItem(i);
    supnode = node.parentNode;
    parentnode = supnode.parentNode;
    parentnode.removeChild(supnode);
}

The final step is just a bit of housekeeping. We want to clean up the dom, so we combine any fragmented text sections.

document.normalize();

And that's it! [citation needed]

Posted by molson at 11:15 AM | Comments (0)

June 26, 2007

Why are you protecting me ... from me?

Anybody that has spent some time with me (and I think all 3.14 readers have) knows that I don't like laws that protect me from me. I'm fully capable of making my own decisions, thankyouverymuch, and if not, I'll fully capable of facing the consequences for my actions. I'm not going to pawn my irresponsibility off on someone else (you didn't tell me I was going to get hurt, so it's your fault and you should pay the hospital bills).

There are a number of laws/regulations that fall under this. Trans fats. Helmets. Seat belts. Many others that are an even hotter debate (think moral issues). In most cases, I agree with the intents of the law. I'll wear a helmet when I ride a bike or motorcycle even though in Illinois I'm not required to. I'll probably avoid trans fats and eat fresher, less prepared foods, but if I want a trans fat, it's my right as an American to eat it. I've always worn my seatbelt in cars, although I'm often lazy if I'm sitting in the back seat.

That being said, I understand, and appreciate, enforcing laws that are on the books. Over the past few months I have seen several instances of "Seat Belt Checkpoints" setup by local police departments. In two cases (Arlington Heights and Melrose Park) traffic on a major thoroughfare was closed down to one lane in each direction. The one in Melrose Park was also a "sober driver check" so I understand bringing it down to one lane, and it didn't really effect traffic anyway. The one in AH, on the other hand, was done during rush-hour on Northwest Highway (U.S. Route 14) and had traffic backed up for quite a bit in each direction. To add to the idiocy of this method, there was a sign way back, without an officer near it, announcing that it was a "seat belt safety check." Now how stupid do you have to be to not put your seatbelt on at that point? You deserve a ticket.

Contrast this to Mount Prospect. About once a week they setup at the corner of Northwest Highway and Main St./Elmhurst/IL 83. This is a fairly long light if you are on 83 going North or South, especially when a train comes (a regular occurrence during the morning rush). When the light is red, 2-3 officers walk down the street, away from the intersection, looking in people's cars. If you don't have a seatbelt on, the officer takes your license, and tells you that if the light turns green, to pull into the parking lot off to the side. Usually they are done writing the ticket before the light turns green. This doesn't adversely effect traffic and seems to be the much more intelligent way to enforce this law.

Bottom line, if you're gonna have stupid laws and enforce them, please don't be stupid with the enforcement. This means you Arlington Heights.

Posted by molson at 10:42 AM | Comments (0)

June 15, 2007

Links for 15 Jun 2007 [del.icio.us]


  • Long Light - This comic sums up how I feel at the intersection of Rand Rd., Elmhurst Rd., and Kensington near my house.
  • Structured Procrastination - I see myself doing this at times...

Posted by molson at 7:43 PM | Comments (0)

June 1, 2007

Links for 01 Jun 2007 [del.icio.us]


  • Synergy - Synergy lets you easily share a single mouse and keyboard between multiple computers with different operating systems, each with its own display, without special hardware.
  • HEAD Sterling Silver Earrings - Gotta love geek clothing/jewelry

Posted by molson at 7:43 PM | Comments (0)