Developing Opera Extensions: My first experience

Posted by Eklavya Mirani on August 4, 2012

Everytime I see a link someone posts without the anchor tag, I, being the lazy one, always wonder if it is possible to make that link clickable. Obviously, if a link is posted, it ought to be clicked. Does the author assume we, "The lazy ones" would actually copy paste the entire thing, open a new tab, paste the link and hit enter and get back to the old page the link was opened from and complete reading it?

If the answer is yes, that link must be pointing to one heck of a page that moves my world, or else it might subtly, very subtly, enter my list of, what I call, "Links I can do without."

Lemme show you what I mean.

http://www.google.com

http://www.google.com

Which one is better? I prefer the one that is clickable, I'd middle click on it and send it to a background tab in my Opera.

So, today I finally completed the first version of my Opera Extension, LinkMoi. What does it do? It makes the non-clickable links/Uri clickable. And if you visit phpBB forums, this might be your lucky day. Most of them have a common rule, "all links must be coded." Well, these links aren't clickable-just coded, so if you want to open it select it (or click 'select all') and add it to the address bar.

With LinkMoi, the link becomes clickable, just click and open. Simple.
(I know Linkify was developed for this, and it has been there for a while...My intention was to implement one myself.)

I wrote a simple javascript to convert all the urls to clickable links, this wasn't hard. I created a button, whose onclick event calls the function that does this job.

Click, and BINGO! Click again and.
.
.
.
WTF!
http://www.google.com becomes http://www.google.com">http://www.google.com.

and I click again.. WTF!x2
http://www.google.com">http://www.google.com becomes http://www.google.com">http://www.google.com">http://www.google.com.

As you might have guessed, href="http://www.google.com" also gets converted. I will not go into my trials and errors, certainly, I don't really enjoy talking about my mistakes :) What I did was to skip those links that followed '>' symbol. Genius, eh? (Hang on, read the next few lines before answering that.)

Once I fixed it, I copied the source of a website I use often and used it in my test page. Didn't work. Check the source and found, the link was wrapped around the 'span' tag.

So much for a genius thought!

I tried catching the '"' along with the link (using ["]? regex) and skip the link which was contained in '"' as they are the ones causing troubles. So, I had to skip a few links in the regex search, as every href="http://..."> lead to 3 false results:

href="http://...">http://
href="http://...">http://
href="http://...">http://

So, I skipped 3 links. Worked. Excellent job, I said to myself.

So I made the extension, zipped and renamed it to LinkMoi.oex and began testing. I found out that some links were being skipped, and the header of a page showed a 'url' it wasn't supposed to.

I digged a little deeper, looked at the source. What I found did another damage to my "Geniusness." Links were also present as part of the images and in that case I recieved only 2 false positives:

src="http://">
src="http://">

So skipping 3 meant I certainly was missing a few links.
Darn!

To fix it, I took a piece of paper and pen, and actually wrote down the possible ways in which links could be posted in a website, between 'span', in 'src', in 'href', as 'url', 'action', etc. So I checked the 9 character substring preceding the link and checked for these keywords, if found skip the links accordingly. And as a default check anything which has '=' in the last two characters is skipped.

Bingo! Works. Checked on a few phpBB forums, MSDN, wordpress and everything works just fine.

So here it is, my first experience developing an Opera Extension. Here's the link to the extension: https://addons.opera.com/en/extensions/details/linkmoi/?display=en

If you want to develop your own extension: http://dev.opera.com/articles/view/hands-on-building-an-opera-extension/