Thursday, July 1, 2010

Buzz Bookmarklet

I found it odd that I couldn't easily find a "bookmarlet" for Buzz that I could easily drag into my bookmarks bar.

Maybe I'm blind, or wasn't looking in the right places... so I wrote one. It's probably broken in some cases, and is fairly rudimentary, but here it is:

Post to Buzz (drag to bookmarks bar)

If interested, here's the code:

/* Buzz bookmarklet, this should work on older browsers*/
var e=encodeURIComponent;
var b='http://www.google.com/buzz/post';
var u=e(document.location.href);
var els=document.getElementsByTagName('meta');
var o=null;
for(var i=0;i<els.length;i++){
if(els[i].name=='description'){
o=els[i];
break;
}}
var m='';if(o!=null)m=e(o.content);
var a='resizable=0,scrollbars=0,width=690,height=415';
window.open(b+'?url='+u+'&message='+m,'_blank',a);
void(0)
/* Compressed version, this would be placed in "location" of bookmark:
javascript:e=encodeURIComponent;b='http://www.google.com/buzz/post';u=e(document.location.href);els=document.getElementsByTagName('meta');o=null;for(i=0;i<els.length;i++){if(els[i].name=='description'){o=els[i];break;}}m='';if(o!=null)m=e(o.content);a='resizable=0,scrollbars=0,width=690,height=415';window.open(b+'?url='+u+'&message='+m,'_blank',a);void(0)
*/

This is a more fancy (shorter) version that uses querySelector:

/*Buzz bookmarklet, uses querySelector, works on FF 3.5+, Chrome, IE8+, Safari 4*/
var e=encodeURIComponent;
var b='http://www.google.com/buzz/post';
var u=e(document.location.href);
var o=document.querySelector('meta[name=description]');
var m='';if(o!=null)m=e(o.content);
var a='resizable=0,scrollbars=0,width=690,height=415';
window.open(b+'?url='+u+'&message='+m,'_blank',a);
void(0)
/* Compressed version, this would be placed in "location" of bookmark:
javascript:var e=encodeURIComponent;var b='http://www.google.com/buzz/post';var u=e(document.location.href);var o=document.querySelector('meta[name=description]');var m='';if(o!=null)m=e(o.content);var a='resizable=0,scrollbars=0,width=690,height=415';window.open(b+'?url='+u+'&message='+m,'_blank',a);void(0)
*/

2 comments:

  1. Cool stuff. Next time you're looking for bookmarklets check out http://marklets.com. Here's a link to a search for 'buzz', looks like there are a few other bookmarklets similar to yours.

    http://marklets.com/Results.aspx?s=buzz

    ReplyDelete
  2. Cool! Thanks for the pointer. I knew they had to be out there somewhere.

    ReplyDelete