forked from GoogleChrome/chrome-extensions-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
33 lines (30 loc) · 951 Bytes
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
chrome.cookies.onChanged.addListener(function(info) {
console.log("onChanged" + JSON.stringify(info));
});
function focusOrCreateTab(url) {
chrome.windows.getAll({"populate":true}, function(windows) {
var existing_tab = null;
for (var i in windows) {
var tabs = windows[i].tabs;
for (var j in tabs) {
var tab = tabs[j];
if (tab.url == url) {
existing_tab = tab;
break;
}
}
}
if (existing_tab) {
chrome.tabs.update(existing_tab.id, {"selected":true});
} else {
chrome.tabs.create({"url":url, "selected":true});
}
});
}
chrome.browserAction.onClicked.addListener(function(tab) {
var manager_url = chrome.extension.getURL("manager.html");
focusOrCreateTab(manager_url);
});