« Geek Day 4 - Greatest application written to date Geek Day 6 - Primary geek fuel (snacks/drinks) »

Geek Day 5 - Quick nifty hacks you're proud of

Posted by Simon Welsh | 8 November 2010 | Comments (1)

I get into trouble for most hacks now, so that rather limits the scope I can respond with. One recent hack I'm rather proud of is a screen scraper I had to write (they don't provide an API for the data I want) that has to login in first. Initally, I was logging in manually then handing off the session cookie. That started breaking for some reason (I found out why later), so, instead of attempting to fix it, I rewrote it to script the entire process.

The login page does some annoying stuff with JavaScript, including setting cookies and appending things to the URL. Which is kinda a bitch to do with cURL. A bit of poking showed that the cookie being set doesn't actually matter and the thing appended to the URL is always the same. So I hacked in a check whenever parsing the content that if it contained the specific marker, it would append and redirect. Login worked, and the cookie handling I had to build for that meant that the rest of the site worked fine.

Another reason hack was for my Facebook SSL Safari extension. Facebook, in its infinite stupidity, has most of the links it puts out hardcoded to http://www.facebook.com/<blah>. This uses more data than they need to, and also means that following a link from the SSL site takes you to the non-SSL one.

To get around this, I had written a nice JS function that used jQuery.livequery to change href/action attributes as new links/forms were added. Turns out livequery cheats and hooks into methods that edit the DOM to know when to update. Facebook doesn't use jQuery, so this doesn't work, so I next tried changing the function that is used by Facebook to add content to the page. This worked great in the error console (best place for JavaScript development) but didn't in my extension. It turns out that the JavaScript sandbox extensions are run in (gives them more power and removes namespacing problems) meant I couldn't change Facebook's JavaScript.

The solution was to use a function that checks for a different amount of <a>/<form> tags every 350ms and loops through them all. I can write it nicer (I thought of how in the shower, as you do) but haven't found the time yet. Could do it now though.


Share on FaceBook

Trackbacks

None
Trackback URL: http://simon.geek.nz/Trackbacks/add/1304

Post your comment

Sign in with Twitter

Comments

  • Duct tape.

    Posted by Caitlin, 14/08/2012 12:38pm (9 months ago)

RSS feed for comments on this page | RSS feed for all comments