Over a million developers have joined DZone.

Crazy Cool Chrome Extension (and How to Dig into the Source)

DZone's Guide to

Crazy Cool Chrome Extension (and How to Dig into the Source)

· Java Zone
Free Resource

Managing a MongoDB deployment? Take a load off and live migrate to MongoDB Atlas, the official automated service, with little to no downtime.

I’m learning some interesting stuff at FluentConf and I’ll talk more about that when the conference wraps, but I want to share something I found yesterday that I thought was really freaking cool. It is a Chrome extension called Momentum. Apparently this was all over the place a few weeks ago so I’m late to the party, but it replaces your “New Tab” screen with an absolutely beautiful (and somewhat useful) design:


You can customize it a bit, but really, it’s just that – a beautiful picture and a greeting. The text, “Patience”, comes from the app prompting you the first time you open a a new tab in the morning:


Which – ok – maybe it is a bit dorky – but I like it. I was also a bit curious about how it worked. Chrome extensions are built with web standards, so I decided to take a quick look at the code.

To find your Chrome extensions, you first need to find where your profile is. Open up chrome://version and you’ll see a “Profile Path” folder. Get to that directory and then enter the Extensions folder. Here you’ll see this wonderfully helpful list of directories (obviously different for each user):


Ok, wow, so, now what? Well next go to your Chrome extensions tag (chrome://extensions/), and find the extension. Make note of the ID value:


You would then enter the directory with the same ID as the extension. At this point, you can dig through the assets and see how they do – well – what they do.


What I found out about Momentum is that the background images are stored locally, which makes sense because you could be offline, and they ship quite a few of them. I also took a look at their JavaScript libraries to see how they built it. It is a Backbone app which is cool, but not a framework I’m really interested in anymore.

The core logic was minified, but that doesn’t really slow you down. I opened a new tab, and then opened dev tools. I went to the minified file and clicked Pretty Print:


Which then gave me nice, readable text:


I then selected all and copied into an editor so I could go through it in a proper tool. For me, the real interesting tidbit I found was how they handle weather. They use YQL, a Yahoo API I’ve blogged about before, but I really don’t see many people using. It is a very cool API so I’m happy to see it in action. If your curious how they use it, this is the block that grabs your current weather:

function n(e) {
    var t = "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent("select * from weather.forecast where woeid=" + e + ' and u="' + s.model.get("unit") + '"') + "&format=json&callback=?";
    $.getJSON(t, function(e) {
        if (e && e.query && 1 == e.query.count) {
            var t = e.query.results.channel.item.condition;
            t && s.model.save({temperature: t.temp,code: t.code,condition: t.text,updated: new Date})
        } else
            console.log("Error getting weather data: Result count not equal to one")
    }).error(function(e) {
        console.log("Error getting weather data: " + e)

Yes – the YQL API is SQL like for data. Very cool stuff. Anyway, check out the extension, and don’t forget you can dig into the code and learn from them as well!

MongoDB Atlas is the easiest way to run the fastest-growing database for modern applications — no installation, setup, or configuration required. Easily live migrate an existing workload or start with 512MB of storage for free.


Published at DZone with permission of Raymond Camden, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}