-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus-icon.js
44 lines (37 loc) · 1.01 KB
/
status-icon.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
34
35
36
37
38
39
40
41
42
43
44
/*
* Sets the state of the extension icon to reflect the state of SessionArmor
*/
function getOrigin(url) {
// capture everything up to the first lone slash
// including the scheme, host, and port
return url.match(/(.+:\/\/[^/]+)\/([^/]|$)/)[1];
}
function domainHasSession(url) {
return localStorage[getOrigin(url)] !== undefined;
}
function newActiveUrl(url) {
if (url && domainHasSession(url)) {
chrome.browserAction.setIcon({
path: "icon-big-green.png"
});
} else {
chrome.browserAction.setIcon({
path: "icon-big-red.png"
});
}
}
function tabUpdated(tabId, changeInfo, tab) {
if (tab.active) {
newActiveUrl(tab.url);
}
}
function tabActivated(activeInfo) {
chrome.tabs.get(activeInfo.tabId, function(tab) {
if (tab.active) {
newActiveUrl(tab.url);
}
});
}
/* handle status icon changes */
chrome.tabs.onActivated.addListener(tabActivated);
chrome.tabs.onUpdated.addListener(tabUpdated);