Goo.gl
EDIT: This information is outdated. Goo.gl has changed their methods for URL shortening. Going to Goo.gl, right-clicking on the input, and going to “Create Search” is sufficient enough now to create a Goo.gl custom search.
Every once and a while I take a look at a feature which is done by another browser or service and figure out ways to get it to work with Opera better than was done with the initial method. I’ve made things like an Opera address bar Twitter client and an Add to Amazon Wishlist button and menu item. Now I’ve decided to create a custom search for Goo.gl. I use Twitter a lot, and I prefer it when I create my own shortened URL’s. Since I use Opera doing such is quite a simple task without much effort. Usually all I have to do is type a keyword before the location I’m already at and it does the rest.
If you’ve been living in this century and have paid any attention what a URL shortening service is should be quite obvious. Its use predates Twitter, but Twitter actually made it have a viable use as simply shortening URLs to remove GET variables or other garbage was necessary to be able to have some URL’s fit within the 140 character limit.
With most any URL shortening service it’s relatively simple to create a custom search for Opera for it, meaning typing bitly http://google.com would create a shortened URL for Google using Bit.ly — provided you had the search created for it using that keyword. Goo.gl is a bit different. There’s no way to access a form to do it from Google’s website. They prefer you to install toolbars or use browser extensions to shorten URL’s using their service. Bastards. Both third party toolbars and third party extensions are a plague, and thankfully neither work on Opera. Custom searches can be created manually, and data URL’s and JavaScript URL’s can be used for custom searches:
data:text/html,%3C%21DOCTYPE%20html%3E%3Chtml%20lang%3D%22en%22%3E%3Chead%3E%3Ctitle%3EGoo.gl%20URL%3C%2Ftitle%3E%3Cmeta%20charset%3D%22UTF-8%22%3E%3Cstyle%3Ebody%2Ca%7Bfont-family%3AHelvetica%2CArial%2Csans-serif%3Btext-align%3Acenter%3Bcolor%3A%23000%3Bbackground-color%3A%23d7d7d7%3Btext-shadow%3Argba%28255%2C255%2C255%2C0.5%29%200%203px%200%3B%7Dh1%7Bfont-size%3A6em%3B%7D%3C%2Fstyle%3E%3Cbody%3E%3Cscript%3Evar%20url%3D%22%s%22%3Bif%28%21url.match%28%2F%5Ehttps%3F%3A%5C%2F%5C%2F%2F%29%29%7Burl%3D%22http%3A%2F%2F%22%2Burl%3B%7Ddocument.title%2B%3D%22%20for%20%E2%80%9C%22%2Burl%2B%22%E2%80%9D%22%3Bvar%20jsonp%3Ddocument.createElement%28%22script%22%29%3Bjsonp.setAttribute%28%27src%27%2C%22http%3A%2F%2Fggl-shortener.appspot.com%2F%3Furl%3D%22%2Bescape%28url%29%2B%22%26jsonp%3Dh%22%29%3Bdocument.getElementsByTagName%28%27head%27%29%5B0%5D.appendChild%28jsonp%29%3Bfunction%20h%28r%29%7Bdocument.body.innerHTML%3D%22%3Ch1%3E%3Ca%20href%3D%5C%22%22%2Br.short_url%2B%22%5C%22%3E%22%2Br.short_url%2B%22%3C%2Fa%3E%3C%2Fh1%3E%22%3B%7D%3C%2Fscript%3E%3C%2Fbody%3E%3C%2Fhtml%3E
This looks like a mess, and is quite like what I created initially for my Address Bar tweet mechanism. I couldn’t for the life of me get a JavaScript URL to work with this, so I had to resort to using the uglier data URL. If anyone out there can accomplish this using a JavaScript URL be my guest. I didn’t want to spend a whole lot of time because at this point it’s essentially a proof-of-concept. Presently this uses JSONP to accomplish its methods, so it does rely on an external website neither you nor I have any control over. If you’re paranoid it’d be a good idea not to use this. It’d be also worth nothing that this could stop working without notice.
To install this custom search follow these directions:
- Go to
Opera → Preferences(orTools → Preferenceson Windows and Unix). - Click on the Search tab then click the Add… button.
- In the input box labeled Name type in
Goo.gl. - Type in your preferred keyword in the Keyword field. I use
googl. - Paste in the Data URL above into the Address field and click OK.
It should be obvious how to use it. I’ve tested this script personally over several weeks, using it for every instance where I’ve needed a shortened URL. If I were to make improvements upon this I would create some redundancy, allowing it to fallback to another method in case the website’s being used for JSONP ever goes down. Perhaps I’ll do that in the future. This is licensed under a Do-whatever-the-fuck-you-want-with-it license; the details of the license are contained within its namesake.