Making ClaraNet Play Nice

UPDATE - 11 Sept 2008: ClaraNet has been upgraded to a new version of ERes which makes this script useless. I'll be working on a new solution soon.

Fellow SCU students: Have you ever wanted to download a batch of files from ClaraNet (ERes) only to be thwarted by obnoxious javascript links that interfere with your download manager? Last night, I got so fed up with ClaraNet (our law school's electronic course reserves system) that I spent all night writing a Greasemonkey script to tame it.

3 Easy Steps For the Impatient:

  1. Install the Greasemonkey extension for Firefox here (or Firefox 3 build here).
  2. After installing Greasemonkey (and restarting Firefox!), click on this script to install it in Greasemonkey: claranetlinkcleaner.user.js.
  3. Visit ClaraNet and enjoy "real" http download links instead of the fake javacript ones that interfere with download managers (I recommend DownloadThemAll).

More info:

My school has an online course reserves system it calls ClaraNet. ClaraNet is actually an instance of Docutek ERes, some expensive, proprietary document management solution.

Don't get me started on all of the issues with ERes. Suffice it to say, it's built on a model of security by obscurity, and relies on dumb hacks to try to maintain control over its documents. The most offensive of these is the javascript link, which looks like this in the page source:

<A href="#" onClick="javascript:pop('documentview.aspx?cid=2128associd=26641','yes','','','documentview');">Class 6</A>

The above ERes code creates an href link to "#" - a meaningless reference to the current page itself. Download managers and spiders rely on the href link attribute to find files to download. So this href="#" link effectively hides all of the files from download managers and spiders. In a properly equipped browser, however, a user clicks on the link, and the onClick attribute fires a javascript called 'pop' which pops up a new window with the actual URL we're looking for (in this case, documentview.aspx?cid=2128associd=26641).

My Greasemonkey script parses out the actual file download URL from each javascript link, then replaces the javascript link with with a conventional html link. So, with my Greasemonkey script enabled, the above section of the page automagically becomes:

<A href="http://claranet.scu.edu/eres/documentview.aspx?cid=2128associd=26641" onClick="">Class 6</A>

This new link has a valid href attribute with the URL to the file we're downloading, and it will work with download managers like DownloadThemAll and FlashGot.

The magic is all enabled by Greasemonkey, a whizbang Firefox extension that lets you run arbitrary javascript on whatever pages you please. Kick ass! Too bad I'm a complete newb javascript and its peculiar idioms, or this might not have taken me 6 hours. Why can't we have python, or perl, or even ruby for browser scripting, instead of this half-baked bastardization? But I digress...

To use this hack, first install Greasemonkey (and restart Firefox). Then come back to this page, and download claranetlinkcleaner.user.js. When you click on the link, Greasemonkey should automatically prompt you to install the script. After you do that, you're set. The next time you visit ClaraNet, the javascript download links will be replaced with valid href's that you can snarf up in your download manager of choice.

It's sad that I had to do this, really. Isn't it an obvious feature that people might want to download all of the files for their class at once? Evidently half-assed security by obscurity prevails over usability at Docutek, which - come to think of it - might just make them a perfect vendor for SCU's IT Department. Sigh.