My first UserJS

As you've probably heard by now, my favorite browser is now free as in beer. The new version of Opera has had the banner ads and registration code removed and is now completely free of cost. I'm not sure what the reasoning behind this chage is, but I'm hoping it will increase Opera's market share. While Firefox has been getting huge amounts of buzz in the media, Opera has been languishing in relative obscurity, despite the fact that it is a superior program in many respects.

This news prompted me to do something I've been meaning to do for a long time: try out User JavaScript. If you haven't heard about it, User JavaScript is a feature of Opera 8 whereby you can write (or download) your own JavaScript files to be run Opera loads a page. If you have enough JavaScript know-how, this gives you almost unlimited power to change anything in the page. You can do everything from disabling annoying scripts a particular site tries to foist on you to adding your own custom content to a page.

My personal foray into this was a fairly simple content addition: add a link to the Google results page to go straight to the "cached text only" page. Call me paranoid, but I like to use the Google cache at work to make some of my surfing harder to track. The normal Google cache link attempts to load external references, so I often prefer to go straight to the text-only page. To do this, I wrote the following: if ( location.href.match(/^http://www.google.com/search/) ) { document.addEventListener( 'load', function (e) { var anchors = document.getElementsByTagName("a"); for(i=0; i<anchors.length; i++) { if (anchors[i].innerHTML == "Cached") { old_href = anchors[i].href; anchors[i].innerHTML = 'Cached</a> - <a href="'+ old_href+"&lr=&strip=1">Cached text only'; } } return true; }, false ); }

It still needs some work. For one thing, the idea of setting the innerHTML doesn't really work, as the dash in the middle ends up as part of the original link. However, it seems that insering an element into the [ac=Document Object Model]DOM[/ac] using JavaScript is only doable if you have a reference to the parent element, which I don't really know how to get. I guess I'll finally have to learn some real JavaScript.

You can reply to this entry by leaving a comment below. This entry accepts Pingbacks from other blogs. You can follow comments on this entry by subscribing to the RSS feed.

Add your comments #

A comment body is required. No HTML code allowed. URLs starting with http:// or ftp:// will be automatically converted to hyperlinks.