February, 2010


28
Feb 10

Translate Youtube Mobile (bookmarklet)

For some reason I run into this issue a lot. I get to a YouTube mobile page on my iPhone, and not wanting to view the video that moment, I save it to Instapaper. But when I go back to view it, it doesn’t work. I get a generic YouTube Mobile page.

But I noticed that the video ID is embedded in the URL. The browser just doesn’t want to see it for some reason. Luckily, Javascript can fix this easily.

Drag the bookmarklet to your Bookmarks Bar. When you encounter a YouTube Mobile page that shows up as a generic “front page,” click the bookmarklet, and it should load the original video you had saved.

Translate YouTube Mobile ← Drag this to your Bookmarks Bar

Here is the source code for those who might be interested.

url = document.location.href;
re = /desktop_uri=(http%253A%252F%252Fwww.youtube.com)?%252Fwatch%253Fv%253D([^%25%26]+)(%25|%26)/;

if ( re.test( url ) ) {
    location = 'http://youtube.com/watch?v=' + RegExp.$2;
} else {
    alert( 'Unrecognized URL format' );
}

UPDATE 28 Feb 2010: new version, fixed regex bug.

UPDATE 08 Jul 2010: new version, improved regex for another case.


25
Feb 10

Shorten Amazon URL (bookmarklet)

Do you find Amazon’s product page URLs ridiculously long? They’re a pain to paste into an IM window or an email. For most product pages, a much shorter version can be used. For instance, you can turn this:

http://www.amazon.com/gp/product/014311638X/ ref=s9_simh_gw_p14_i1?pf_rd_m=ATVPDKIKX0DER &pf_rd_s=center-2&pf_rd_r=1V6X9CF9300FXVK16QJY &pf_rd_t=101&pf_rd_p=470938631&pf_rd_i=507846

into this:

http://www.amazon.com/gp/product/014311638X

Drag the bookmarklet to your Bookmarks Bar. When you’re on an Amazon product page and want to shorten the URL, click it. You’ll be taken to the same page, with the short URL instead.

Shorten Amazon URL ← Drag this to your Bookmarks Bar

For those who are interested, here is the source code.

var url = document.location.href;

var dp_re = /\/dp\//;
var gp_re = /\/gp\/product\//;

if ( dp_re.test( url ) ) {
    location = url.replace( /^(http:\/\/[^\/]+).*(\/dp\/[^\/]+)\/.*$/, "$1$2" );
} else if ( gp_re.test( url ) ) {
    location = url.replace( /^(http:\/\/[^\/]+).*(\/gp\/product\/[^\/]+)\/.*$/, "$1$2" );
} else {
    alert( "Unrecognized URL format" );
}