DuckDuckGo Transition Assistant

I’ve recently switched to DuckDuckGo.com as my default search engine in Chrome. What I noticed, however, is that I kept wondering after every search what would the search result be on Google, and did I miss perhaps some important link.

To help me with this situation, the DuckDuckGo (DDG) Transition Assistant was born: a super simple free Chrome extension that gives you a little button on the right side of the Address Bar that only works when on duckduckgo.com. When clicked a window shows the results of the search from Google.

I had a grand vision of how I wanted to show the search results, but in reality there were so many road blocks that I had to settle with a simple iFrame showing what you’d see when you visited Google directly.

The code consists of 3 files:

  1. image file (favicon)
  2. manifest.json
  3. popup.html

Here’s the code.

manifest.json

//Author Raivo Ratsep, 7/9/2011
{
  "name": "DDG Transition Assistant",
  "homepage_url": "http://raivoratsep.com/177/duckduckgo-transition-assistant/",
  "version": "0.1",
  "description": "Helps you transition to DuckDuckGo search engine by allowing to check their search results against Google search results..
  you know...when you just can't live without knowing what Google would've shown."
,
  "browser_action": {
    "default_icon": "icon-v2.png",
    "popup": "popup.html"
  },
  "permissions": [
    "tabs", "http://duckduckgo.com/*"
  ]
}

popup.html

<head>
<style>
body {
  min-width:600px;
  height: 500px;
}
</style>

<script>
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
        var query = request.query;
//      var domainSplit = sender.tab.url.match(/^[\w-]+:\/*\[?([\w\.:-]+)\]?(?::\d+)?/)[1];    
         
        var frame = document.createElement('iframe');  
        frame.setAttribute('width', '100%');
        frame.setAttribute('height', '100%');
        frame.setAttribute('frameborder', '0');
        frame.setAttribute('id', 'rtmframe');
       
        if(query == 'xx-error') {
            frame.setAttribute('src', 'http://www.google.com/');
        } else {
            frame.setAttribute('src', 'http://www.google.com/#q=' + query);
        }

        document.body.appendChild(frame);
});

// execute this little script in the DDG page context, so that we can pickup the query string.
//TODO: pick it up from URL instead of parsing the form on page
chrome.tabs.executeScript(null, {code:"var ddg_query; if(document.getElementById('hfi') != null) { ddg_query = document.getElementById('hfi').value; } else { ddg_query = 'xx-error'; } chrome.extension.sendRequest({query: ddg_query});"});

</script>
</head>
<body>
</body>

The extension can be installed from here.

I’m pretty sure you can inspect the contents of what you’re running by right clicking on the little extension icon and selecting Inspect popup.

That’s that.

Please leave feature requests/bug info in comments.

RSS feed for comments on this post. TrackBack URI

Leave a Reply