odyniec.net

Archive for the ‘Greasemonkey’ Category

Weekend Project(s): Cardboard Cat Chaise / Greasemonkey Unit Conversion Script

Saturday, January 3rd, 2009

Every once in a while I like doing some DIY stuff just for the fun of it — I suppose it’s my deeply buried need to create something that is physical and not source code, for a change. Some time ago, I came across building instructions for a cardboard cat chaise, and I thought it might be fun to make. Besides, I had no doubts my cats would like it, as they’ve always demonstrated an evident fetish for cardboard boxes.

So, the day came yesterday — I got a big cardboard box, prepared the tools, arranged a workspace on the floor, and began reading the instructions. To my disappointment, all the dimensions in the text turned out to have been given in inches, which seemed perverted for a normal, healthy, metric-oriented person that I am.

Of course, it wouldn’t be a big deal if I just took a calculator, did a few multiplications, and got the respective values in centimetres. Or I could use the mighty unit conversion capabilities of Google search. But then I thought to myself — hey, isn’t this the 21st century, Web 2.0, and stuff? I shouldn’t be forced to do such a tedious task of entering numbers and doing the calculations, this bloody machine/Web/whatever should do it for me. With this in mind, I turned to Userscripts.org to see if there was a Greasemonkey script that could parse those awful inches and convert them to lovely centimetres right there on the webpage. But, bummer — it seemed there was no such script.

This is where my need to create something physical had to retreat for a while, as the more powerful need to immediately transform the idea for a conversion script into an implementation was taking over. I quickly coded a basic script that converted inches, feet, yards, and miles into centimetres, metres, and kilometres, and displayed the result in a tooltip when the mouse cursor was placed over the value in question, like this:

US to Metric

To make the script a bit more useful, I also added conversion rules for units of mass (ounces and pounds to grams and kilograms) and temperature (Fahrenheit degrees to Celsius). If you want to give it a try, you can grab it from Userscripts.org.

And the chaise? It turned out quite well, and the cats started using it instantly. Here’s one satisfied customer:

Happy cat on a chaise

If you compare my result with the original one from the article, you’ll notice I went with a more primitive IKEA-ish design, but my cats are just simple unpretencious DSHs and they don’t like fancy furniture.

BrightenUp Greasemonkey Script

Thursday, November 6th, 2008

In my last post, I got somewhat excited about the idea of making a Greasemonkey script that would allow you to adjust the brightness of images on websites. One afternoon a few days ago, having nothing better to do, I wrote the script — and it sort of works. More precisely, it works only on some websites.

The script, like the imgFx plugin, makes use of the canvas HTML element. Among other things, canvas lets us retrieve the image’s pixel data as RGB values. To make an image brighter, we need to read all the pixels, increase their RGB values, and use the new pixel data to redraw the image. Sounds rather simple, but there is one fundamental problem. Due to security restrictions, Firefox will let us read the pixel data only if the image originates at the exact same domain as the website itself. Even if it’s just the sub-domain that is different, it won’t be allowed. So, if you have a website at somedomain.com, but your images come from images.somedomain.com, the script won’t work with it.

Anyway, in case you’d like to try out the script, here it is: brightenup.user.js

I’ve checked the most popular image hosting websites, and it seems only ImageShack meets the requirement of images originating at the exact same domain as the page on which they appear. Thus, the script is set to execute on *.imageshack.us. Here’s a sample image that you can test it on (no goatse, and safe for work, I promise):

http://img479.imageshack.us/my.php?image=letescaupeje0.jpg

Move the mouse cursor over the image, and two buttons will pop up in the top left corner. Press “+” and “-” to make the image more or less bright.

Update (Nov 8):
I’ve uploaded the script to Userscripts.org for the world to see — there it is.