Wednesday, March 13, 2013

Yes, Pandora, I'm Still Listening

Lately I've been listening to Pandora as background noise while coding.  Like you, I've clicked the "I'm still listening" button more times than I'd care too.  Today I decided to do something about it; I'm not talking about paying to upgrade Pandora either.

I'm sure someone out there has already written a perfectly good Greasemonkey script that I could use, but where is the fun in that.  It has been a while since I wrote anything in JavaScript so I figured this would be a great opportunity to clear away any cobwebs.

The first thing that needs to happen is to be notified of any changes to the DOM.  This is quite easy using MutationObserver defined in the DOM4 specification.  The callback is provided with a MutationRecord that contains the addedNodes as a property.  We can then search the addedNodes for the "I'm still listening" button.

06/10/2013 Update - I modified the script to only search the addedNode and not addedNode.parentNode due to 'a.still_listening' being found in more than one mutation.  I had a problem where the music was being paused due to multiple clicks() on the button.

My browser of choice is Chrome, and unfortunately it no longer allows users to install .user.js scripts just by opening them.  You now have to open the Extensions window and drag/drop the file onto the page.  Although I haven't tested it, the script should work in Firefox w/ the Greasemonkey extension.

No comments:

Post a Comment