Recently in code Category

Automatically add Gadgets to

I found a post detailng a new feature on, making it possible to automate adding a Gadget. Now I can provide links to add the Analog Clock or Livetris to your profile.

The following links will open a new window to and add the respective Gadget.

Tetris on - Livetris

For my next Gadget, I give you Livetris. It's a completely DHTML re-implementation of the classic puzzle game. It's still pretty basic right now, and only has 10 different speed levels (currently non-configurable, so you have to start at level 1 and work your way up). Block randomization needs some tweaking, since right now it's all too likely to end up with a long string of crap blocks without the bar or square you need to complete a set of lines. I also need to do some work on the scoring, as right now there's no bonus for clearing multiple lines at once. Finally, I'm still tweaking piece colors until I find something I really like, but that's the beauty of a Gadget -- I can make all of the changes I want, and you'll see that reflected on without any user intervention.

As with my Analog Clock Gadget, this one continues to use the awesome JavaScript VectorGraphics library. This is a very robust and powerful tool, and I highly recommend others check it out.

I plan to eventually put my Gadgets up on the Microsoft Gadgets site, but for now you can use these installation instructions:

  1. Copy
    to your clipboard.
  2. On, select Add Content on the sidebar and then Advanced.
  3. Paste the Gadget URL into the Add a Gadget by URL textbox.
  4. Select the Add button.

Compatibility notes: For now, this Gadget is IE-only due to the way I'm handling keyboard input. I hope to get this working with Firefox soon, but I figured I may as well release what I've got right now. Analog Clock Gadget


With the launch of Windows Live yesterday, I decided I should try my hand at writing a Gadget (yes, I know has been doing the Gadget thing for a while, and is nothing more than a re-branded What better than a simple Analog Clock? Thanks to the JavaScript VectorGraphics library folks for an awesome DHTML drawing library.

The Analog Clock Gadget works with both and

To install (cribbed from Microsoft Gadgets' installation instructions):

  1. Copy
    to your clipboard.
  2. On, select Add Content on the sidebar and then Advanced.
  3. Paste the Gadget URL into the Add a Gadget by URL textbox.
  4. Select the Add button.

I've updated the depiq user script, now version 2, to support Slashdot's recent HTML 4.0 + CSS site redesign. You'll want to remove the old script, as the script name has changed to represent the version update.

While the change is nice, and fixes some weird HTML (why was the first article on a page different than all of the rest), they still haven't made it very nice. For example, they have a div with an id of "articles", which you would think contains a bunch of articles. That it does, but it also contains storylinks (the "Read more" links under each article) and some other crap. Why doesn't an article encompass its own storylinks? Why are there other bits at the end of the div, like the "Yesterday's news" link? Oh well, I'll keep at it so long as they keep posting Roland stories.

Depiq user script update

I've updated the depiq user script. I've solved the problem of disembodied "Read More" links (Slashdot's HTML is FUBAR; the first story on a page is encapsulated in a paragraph except for its "Read More" bits, while subsequent stories on a page do not have the same parent paragraph). Because I'm more confident about the script's capabilities now, I've also changed the include list to handle all slashdot categories. Internally, I removed the closure (closures are not memory-friendly in IE), refactored the code a bit into functions, and added some logging (through the GM_log() functionality, you'll see it either in the Turnabout console in IE or the Javascript console in Firefox) to track the editor that posted each story that was found and to give a total count of how many stories were removed. Finally, I can't seem to keep the filenames straight. I'm sticking with "depiq.user.js" for now. You may have to uninstall the previous script before installing this new one.

As always, the script has been tested with IE/Turnabout and Firefox/Greasemonkey. Since this script is just basic DOM walking and manipulation, it should work in Opera 8 as well, but I've not done any testing there.

Depiq user script

Since I created a "userscripts" category on my blog, I figured I should post my other user scripts (okay, "user script" singular for now) in this category for easy access.

Here's the depiq user script. It removes Roland Piquepaille-submitted stories from the Slashdot home page (exactly why you would want to remove these submissions is explained in the comments of pretty much every Roland-submitted story -- ie, if you have to ask, you probably don't care enough to remove them). The inclusion list is only the main Slashdot page, so Roland stories will still show up in other sections (you could change the inclusion list, but I haven't tested that). It's not perfect, thanks to Slashdot's horribly awful HTML code. You might see some parentless "Read More" links, for example. That just tells you that the script is working.

Since I'm an Internet Explorer user (gasp!), this script works with both Firefox/Greasemonkey and IE/Turnabout (Turnabout is now my choice of Greasemonkey-like IE plugins, since I killed GreasemonkIE -- I really liked that name; maybe Turnabout could rename themselves to GreasemonkIE?). It might work in Opera 8, but I haven't tested it there. Feel free to let me know if it does or doesn't work, or update the script to work with Opera.

Any future scripts will be Firefox/Greasemonkey- and IE/Turnabout-compatible. I'll do my best to support Opera 8, but it's secondary to the other two (sorry, Opera users).

I hacked around a little bit on the forza-stats user script, and ended up with this:

  • Added a "podium percentage" statistic. This takes the number of 1st, 2nd, and 3rd place finishes (or as I like to call them, "win, place, and show"), and divides them by the total number of races.
  • Added an onsubmit handler to the gamertag input form. If you hit enter on the input box, it will act as though you clicked "Set".
  • Changed the color and opacity of the statistics bar. I changed it to a greyish color that better fit the Forza theme, and added a slight transparency so that you can see the header graphic obscured by the bar. Strictly cosmetic, since the bar wasn't obscuring any clickable bits, but it's still a nice change.
  • Added some nasty browser-detection code so that the bar can be "position: fixed" on Mozilla. IE doesn't support "position: fixed", and the hacks to support a fixed-like layout assume you have full control over the web page. Since I really don't want to try to completely re-layout the Forza community pages, I did this hack so that at least Firefox users can have a fixed bar. I was very hesitant about adding this browser check, since it may completely fail if you've changed Firefox's userAgent string to mimic IE, but I decided it was worth doing because Firefox has reached the point where it's an accepted browser and only really stupid pages require it to identify itself as MSIE. Worst case, if you've changed Firefox's userAgent to look like MSIE, the statistic bar will be positioned abosolutely at the top of the page rather than as a "floating" fixed element.
  • Added some cleanup code to unhook onclick and onsubmit handlers. This is an attempt to help stem IE's javascript memory leaks. Memory is still leaked, but the forza-stats script should be nicer about not leaking as much memory.
I also spent some time seeing if I could make this script work with Opera 8's user scripting support, but reliance on GM_* functions makes this difficult. I tried using a script that implements the GM_* functions, but ran into several problems:
  1. The GM_getValue implementation in that script is broken. It's trying to eval the stored value, which doesn't work when storing simple strings.
  2. The GM_xmlhttpRequest "implementation" is simply an aliasing of Opera's XMLHttpRequest object. That's not enough for a proper implementation of GM_xmlhttpRequest.
If those two items in the compatibility script were fixed, or if a different compatibility library was used (I don't normally use Opera, so I don't know what exists in terms of mimicking Greasemonkey functions), forza-stats may work in Opera. However, given the differing CSS implementations across browsers, the bar itself probably wouldn't look right (Opera supports "position: fixed", but my browser check may not handle Opera properly; the width of the bar may be incorrect; Opera doesn't support the opacity style or the filter style which is used to do opacity in IE; etc).

As before, forza-stats is compatible with both Mozilla/Greasemonkey and IE/Turnabout.

About this Archive

This page is an archive of recent entries in the code category.

cars is the previous category.

games is the next category.

Find recent content on the main index or look in the archives to find all content.



OpenID accepted here Learn more about OpenID
Powered by Movable Type 5.01