I love using the twitter web interface whenever i’m not at my primary computer but after getting used to the way Twitter for Mac handles link shortening I’m often frustrated with Twitter.com.

Twitter for Mac

The letter count of a tweet with a long link in Twitter for Mac displays what the character count will be after the link is shortened and allows me to post as is.

Twitter for Mac's Link Shortening

Twitter.com

On Twitter.com, a tweet with a long link displays the current character count rather than taking into account that the link will be shortened. There is also no way to shorten a link with the default interface and I’m unable to post because the combination of my un-shortened link and the text in my tweet is over 140 characters.

Twitter.com's Link Shortening

The Solution

I wrote a quick bookmarklet that will parse a tweet in the twitter.com interface and open it in a share window with the shortened link. While this isn’t an ideal solution it’s much faster than going to bit.ly, shortening the link and going back to twitter.com to tweet it.

The Code

var r = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
var theurl = "";
var thetext = "";
$($(".twitter-anywhere-tweet-box-editor").val().split(" ")).each(function(i,v) {
	if(r.test(v)) {
		theurl = v;
	} else {
		thetext += v + " ";
	}
});

window.location.href="http://twitter.com/share?text="+escape(thetext)+"&url="+escape(theurl);

The Bookmarklet

Twitter Shorten