/**
 * @author Joseph
 */

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
    console.log("received method: "+request.method)
    switch(request.method){
        case "getLocalStorage":
            sendResponse({data: localStorage});
            break;
        case "setLocalStorage":
            window.localStorage=request.data;
            sendResponse({data: localStorage});
            break;
        case 'openSettings':
            chrome.tabs.create({url: chrome.runtime.getURL("options.html")+'#'+request.anchor});
            sendResponse({data:{tabid:sender.tab.id}})
            break;
        default :
            sendResponse({data:[]}); // snub them.
    }
});

function syncData(){
    todayTasks(function(){
        completedList(function(){
            todoList(sync);
        })
    });
}

function routinelyCheck(){
    isUserSignedOn(hostPrefix(),'autologin','/signin',function(){
        isUserSignedOn(pomoHostPrefix,'session','/account#login',syncData);
    });
    setTimeout(function(){
        routinelyCheck();
    },30*60*1000);
}

function isUserSignedOn(hostUrl,name,loginUrl,callback) {
    chrome.cookies.get({"url": hostUrl, "name": name}, function (cookie) {
        if (cookie) {
            localStorage.setItem(hostUrl+name, cookie);
            callback();
        } else {
            localStorage.removeItem(hostUrl+name);
            notifyLogin(hostUrl+loginUrl);
        }
    });
}



    routinelyCheck();


@@ -1236,32 +1236,65 @@
   if (cookie) %7B%0A
+            console.info(cookie)%0A
             loca
@@ -1314,24 +1314,28 @@
 tem(hostUrl+
+%22/%22+
 name, cookie
@@ -1334,16 +1334,21 @@
 , cookie
+.name
 );%0A     

normalize the cookie key