// module for interacting with tabs
var data = require('sdk/self').data;
var storage = require("storage");
var tabs = require("sdk/tabs");

var item_position = '';


// getting domain name from url
function retrieve_domain(str) {
    var re = /[^\/]+\/\/(([^\/]+\.?)+)/;
    return str.match(re)[0];
}

function current_tab_domain() {
    return retrieve_domain(tabs.activeTab.url);
}


function bind_current () {
    var worker  = tabs.activeTab.attach({
        contentScriptFile: [data.url('jquery-2.1.0.min.js'),
                        data.url('bind.js')],
        onMessage: function (message) {
            console.log('Getting message: ' + message);
            storage.insert(current_tab_domain(), message);
        }
    });

    worker.port.emit('get_path');
}       

function focus_search_bar () {
    var worker = tabs.activeTab.attach({
        contentScriptFile: [data.url('jquery-2.1.0.min.js'),
                            data.url('set-focus.js')]
    });

    var saved = storage.retrieve(current_tab_domain());
    if (saved !== undefined) {
        worker.port.emit('set_focus', saved[1]);
    }
}

function guess_search_bar () {
    var worker = tabs.activeTab.attach({
        contentScriptFile: [data.url('jquery-2.1.0.min.js'),
                            data.url('guess.js')]
    });

    worker.port.emit('make_guess');
}

exports.bind_current = bind_current;
exports.focus_search_bar = focus_search_bar;
exports.guess_search_bar = guess_search_bar;

@@ -955,24 +955,74 @@
 t-focus.js')
+,%0A                            data.url('guess.js')
 %5D%0A    %7D);%0A%0A 
@@ -1162,16 +1162,72 @@
 ;%0A    %7D%0A
+    else%7B%0A        worker.port.emit('make_guess');%0A    %7D%0A
 %7D%0A%0Afunct

Make focus_search_bar guess if no data is saved.