Programming is a massive part of my working life. Regardless of what I'm doing on my PC, in the back of my mind, I'll be thinking of a program or script that could make whatever I'm doing easier. Any repetitive task that requires a series of similar actions is immediately broken down by the little decompiler in my brain and translated into pseudo-code, ready for input into my language of choice. Recently, I decide to convert one of my programs into a Chrome extension, mainly to familiarise myself with the process. Despite my efforts, however, I failed miserably.
The program I selected was written in C#, and runs in the background while I edit Lifehacker. It is not overly fancy; it monitors the clipboard and uses regular expressions to detect certain bits of HTML. When it finds a match, it converts this HTML into a custom format used by our back-end. This allows me to do a simple Ctrl-X, Ctrl-V to convert any offending piece of HTML quickly into something the content management system understands.
It also converts links from Google into actual URLs — go ahead, try and copy a link from a Google search and paste it. The result won't be what you expect. There's even a feature that automatically converts clipboard URLs into Bit.ly links, complete with the web page title of the URL, ready for posting on social networking sites.
Adding up the time it's saved me so far would easily run into hours.
Anyway, as I said, all it really does is keep an eye on the clipboard and perform some simple text replacement routines. This, I thought, would be easy to port to a Chrome extension.
What you don't get is a development environment, though that's hardly surprising. You can grab Notepad++ or PSPad, if you require syntax highlighting. In a spot, vanilla Notepad — or any text editor — will do. Really, whatever IDE you like best is more than good enough.
The problems I encountered were caused by my transition from the comparatively open and unsecured C# / .NET environment, to the tightly-controlled, sand-boxed arena of the modern browser, where even reading the clipboard is subject to intense scrutiny.
In C#, reading / writing to the clipboard is achieved like so:
string s = Clipboard.GetText();
s = "Frogs!";
Clipboard.SetText(s); // You could use this directly as well.
Except that to change the text, you need an input field on the background page in which to paste the clipboard to first. You can then change the text, before reading it back onto the clipboard with a copy command.
I know security is paramount, but really, this just seems extreme. The really silly part is that people have been using Flash to get around this, and when it comes to security, well, Flash is certainly no darling. I would go as far to say the act of locking down the browser in this fashion promotes bad behaviour as coders look for workarounds.
Of course, having to dance with the clipboard didn't put me off immediately, it was the other limitations I eventually encountered. In the end, it was enough to make me stick with C#, as getting what I wanted accomplished in .NET didn't require jumping through a hundred hoops.
I'm keen to write an extension in the future, though I feel like I'll have to set my sights lower if I want to actually finish it.