I love this M3U generator bookmarklet that Andy Baio pointed to a couple days ago, but I'd like to know whether the page I'm viewing links to any MP3s before I click. Playlist is a Greasemonkey user script that does exactly what Hublog's bookmarklet does, but notifies the user that a playlist has been generated with an icon in the top right corner of any page linking to MP3s.
if (href.match(/\.mp3$/)) { links.push(href); }to this:if (href.match(/\.mp3$/)) { links.push(href.replace(/%20/g, "%2520")); }I haven't tested any other special chars so it's probably not perfect, but at least it works for spaces.I haven't tried this, but if the above trick works then the general case should be:
if (href.match(/\.mp3$/)) { links.push(escape(href)); }Appending this code to line 41 will include ogg/vorbis files, although there's probably a better way to do this with some kind of OR statement for the contains() xpath function on line 32.
xpath = '//a[contains(@href, "ogg")]'; var oggs = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (i = 0; i < oggs.snapshotLength; i += 1) { href = oggs.snapshotItem(i).href; if (href.match(/\.ogg$/)) { links.push(href); } }So, the bookmarklets are great, alf -- wouldn't have thought of this on my own. But suggesting them sort of misses the point. The Greasemonkey script is automatic. I keep seeing that little icon in the top right and thinking, "cool, there's audio here." And that's miles from thinking, "I wonder if there's audio here" and then clicking the bookmarklet on every one of the 50 kazillion pages I view every day, only to find out that, you know, on most there isn't.
Some smart folks call this manufactured serendipity. And I think it rocks.