03.31.2004 - Hotmail Link Decrapulator
A friend of mine uses Hotmail for a secondary email account, and today approached me with a favor to ask.
I've never used Hotmail before, but it apparently has a particulary annoying feature where it mutilates any links it finds in an email so that when you click on them they open in a new window contained within a frameset. The top frame contains the MSN logo, along with the terribly important message "You are visiting a site outside of Hotmail. To return to Hotmail, close this browser window.".
My friend rightfully hates this and asked if I could write a favelet that would stop Hotmail from doing it. Never one to say no, I've obliged by providing the Hotmail Link Decrapulator Favelet.
All it does is loop over document.links, checking them for the "_action=" argument in the urls and replacing the link's href attribute with the value of that argument, thus effectively stripping out all the garbage in the link and allowing you to view your page in peace. Of course, if Hotmail ever changes the format of those links, this will stop working.
Until that day, this should do the trick. If you're a Hotmail user, you can right click the link above and select "Boomark This Link" or "Add to Favorites" depending on your browser of choice.
03.23.2004 - getElementsByName vs. getElementById
I was first made aware of the painful slowness of document.getElementsByName when I was writing Web Paint. Looping over 1,024 div elements using this method was so slow that I often worried that my browser was going to lock up and possibly explode from the exertion. To compensate, I ended up giving each "pixel" a unique ID and using document.getElementById. The resulting increase in speed of execution was astonishing.
Another project that I am currently working on reminded me of this, so I decided to write a little benchmark script to see just how much of a real difference there was. The test works like this: on load, a javascript function creates one hundred DIV elements that share a like name and id attribute of "mDiv". It also creates another one hundred div elements id'd "nDiv" + i, so nDiv0 through nDiv99.
Two buttons call two seperate functions. The first loops over the length of document.getElementsByName("mDiv") and sets each DIV element's innerHTML property to a zero length string, i.e., "". The second button calls a nearly identical function that loops from 0 to 99 and sets each nDiv+i element's innerHTML property to a zero length string.
Each function creates a Date object at its start and another at its finish and then subtracts and alerts the elapsed time. Here are the results on my 1.6GHz P4 with 512MB of RAM running on WinXP:
Browser | getElementsByName | getElementById |
Firefox 0.8 | 120 - 130 ms | 40-80 ms |
Mozilla 1.6 | 90 ms | 30-50 ms |
Opera 7.2 | 290 ms | 270-280 ms |
Netscape 7.02 | 100-110 ms | 40-70 ms |
Konqueror 2.2.2* | 360-721 ms | 253-400 ms |
MSIE 6 | 20 ms | 30 ms |
As you can see, getElementById is always faster than getElementsByName, except in MSIE. Now, assuming there is no flaw in my code, what could the reason for this be? Especially considering that I'm expecting the javascript parser to figure out that I mean "nDiv63" when I say "nDiv"+i, which just by nature really should be awfully slow.
My first thought on this was that getElementsByName could be a programmatic alias to document.all considering IE's implementation of getElementsByName. However, the same test using document.all is slower at 50 ms. So -- I have no idea what the story is here. Have a look at the benchmark page for yourself and see what your results are, and if you've any insight feel free to post your thoughts.
* Konqueror test was run on an 800MHz box with 256MB of RAM. I really only posted it's results as a reminder to myself that my linux box is in horrible condition and that I ought to upgrade it.
03.12.2004 - Style Sheet Viewer Favelet
At work we're in the process of re-vamping our main web based application to fall in line with XHTML/CSS standards with a very CSS Zengarden approach to templatizing the documents -- the idea being generalized markup with CSS controlling the presentation...you know, the whole presentation/markup seperation dogma.
In working on it, I've found it a bit of a pain in the ass to consult the various style sheets that control each individual template's appearence (based on myriad rules and variables) to see who's doing what and where, so once again it's a favelet to the rescue.
This newest addition to the Tools section is the Style Sheet Viewer for Mozilla & Firefox. It will create a DIV element that overlays the document and list all the style sheets referenced therein with their selectors and rules. It works for LINK's, inline STYLE's and one-level @import rules. (Right click that link and hit "Bookmark this Link")
I've tested it on a number of sites and the only ones it has difficulty with are sites that reference style sheets on different domains, such as Gamespot, which throws an "Access to restricted URI denied" exception, and Simon Willison's site, which causes it to throw a long-winded component exception which shall require further investigation.
As an aside, while researching this project, I came across the documentation for ownerRule on Mozilla's Gecko DOM Reference.
"Note that if the value of the ownerNode property on the current STYLE element is NULL, then then ownerRule returns the rule that blah. And vice versa."Ha!
02.25.2004 - Dynamic Date Dropdown v2.0
A visitor to the site requested a modification to the Dynamic Date Dropdown, specifically that it would generate the dropdown with future dates rather than dates in the past.
So I've modified it to take an additional boolean argument to manage this. Passing the function a "0" will cause it to create "days" number of options into the future, while passing a "1" will have it create "days" number of options into the past.
02.22.2004 - speak updated/fixed
I was skimming through my access log earlier and noticed that someone was apparently displeased with the application I wrote last July that would parse a phrase you type in and then "speak" it back to you using the Merriam-Webster pronunciations keys. I base this assumption on the following url:
http://slayeroffice.com/code/speak.php?broken%20piece%20of%20garbage
That along with another far more colorful phrase clued me in that perhaps there was a problem -- and yes, there was. It wasn't working at all, so, I've fixed it. It even works in Mozilla, Firefox and Netscape 7 now.
That said, if you find something on the site that doesn't work, tell me! There's a lot of stuff here and I don't check it every day to make sure something hasn't changed somewhere that would cause it to break. Cursing into my access log doesn't help anything in most cases, though some of it is fairly amusing.