Home | History | Annotate | Download | only in cookies
      1 <script>
      2 
      3 chrome.cookies.onChanged.addListener(function(info) {
      4   console.log("onChanged" + JSON.stringify(info));
      5 });
      6 
      7 function focusOrCreateTab(url) {
      8   chrome.windows.getAll({"populate":true}, function(windows) {
      9     var existing_tab = null;
     10     for (var i in windows) {
     11       var tabs = windows[i].tabs;
     12       for (var j in tabs) {
     13         var tab = tabs[j];
     14         if (tab.url == url) {
     15           existing_tab = tab;
     16           break;
     17         }
     18       }
     19     }
     20     if (existing_tab) {
     21       chrome.tabs.update(existing_tab.id, {"selected":true});
     22     } else {
     23       chrome.tabs.create({"url":url, "selected":true});
     24     }
     25   });
     26 }
     27 
     28 chrome.browserAction.onClicked.addListener(function(tab) {
     29   var manager_url = chrome.extension.getURL("manager.html");
     30   focusOrCreateTab(manager_url);
     31 });
     32 
     33 </script>
     34