George Papadakis / Blog

Hello, my name is George Papadakis (aka phaistonian) and this is my humble blog (RSS feed)

BSync: Syncing for Chrome Extensions

Wednesday, 3 February 2010 7:34 pm, Comments

Developing Chrome Extensions is a pretty fun thing to do. In fact I have already developed some on my spare time, both for fun and to add some extra functionality to my browser of choice.

One thing I could use during this rather creative (and fun) ride was a way to sync data (and preferences) to all those other computers I use daily, and thus not having to enter/edit stuff over and over again.

Then I had this little epiphany; Chrome comes with a built-in bookmark syncing, so why not utilize this very functionality for a different purpose? 

And so I did.

At first this alchemy wasn't that successful. I stumbled upon quotas and other unexpected walls I had no idea about. However, Chrome guys were very helpful and walked me out of this mess quick enough.

The first extension using this technique was Chrome Notepad. As mentioned above, the whole thing didn't play really well at first, but after a while it did. 

Then I spent like 8+ hours (yeah I suck at coding) building a "smart" abstract Class, complex enough to handle all the syncing needs I could think about, yet simple enough to use in a snap when needed.

The class was named BSync (cause I suck and naming too), and it's already in use in Chrome Notepad and My Alerts  (I am planning to incorporate it in more extensions in the future).

Here is a sample code that instantly brings syncing to any extension.

this.sync = new BSync({
        getUpdate       : function() {
                // Return current update timestamp related to the extension
        },
        
        onRead          : function(json) {
                // Read stuff
        },
        
        onWrite         : function() {
                // Write stuff
                this.write(DATA_JSON);
        }
}).start();

BSync is running smoothly, as it should, for some days now. Once it's "officially" okay and polished to the extend it has to be, I am planning to provide a link here for people to download.

Some may actually use/need it, who knows. I did.

UPDATE: Here is an update. Get there and download the Class if you care.

Powered by Pathfinder Blogs