Nav links

Friday, 9 June 2006

Let's bookmark bookmarklets

When I click on the URL of an mp3 file in Firefox I want that file to be streamed via Winamp. Instead, Firefox downloads the file in its entirety before passing the file on to Winamp. To get around this I have been copying the URL into the clipboard, opening Winamp, then telling Winamp to play that URL directly. Whilst this works, it is a little inconvenient. A much nicer solution is to use a bookmarklet, such as HubLog's client-side M3U generator. Just bookmark the generator, then when you want to play the mp3s on a webpage just click the bookmark. What magic!



As with all good things on the internet, the code is there for all to see:



javascript:
a=document.getElementsByTagName('a');
s=new Array();
for(i=0;i<a.length;i++){
if((a[i].href)&&(a[i].href.match(/\.mp3$/))){
s.push(encodeURIComponent(a[i].href));
}
}
var newline=encodeURIComponent('\n');
var m3u=s.join(newline);
if(m3u){
location.href='data:audio/x-mpegurl,'+encodeURIComponent('#EXTM3U\n')+m3u;
} else {
alert('no links found');}


It works by grabbing all of the links to mp3 files, then uses the lovely (though underused) inline data facility to create an m3u playlist in situ to pass to Winamp. All hail bookmarklets!