-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
41 lines (33 loc) · 1.03 KB
/
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
34
35
36
37
38
39
40
41
function main() {
"use strict";
function checkPage(tabId, changeInfo, tab) {
if (tab.url.indexOf('https://soundcloud.com') === 0 || tab.url.indexOf('https://play.spotify.com') === 0 || tab.url.indexOf('http://www.pandora.com') === 0) {
chrome.pageAction.show(tabId);
}
}
var isActive = false;
function toggleExt(tab) {
isActive = (isActive ? false : true);
updateIcon(tab, isActive);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {active: isActive});
});
}
function updateIcon(tab, isActive) {
var icon = {
"tabId": tab.id,
"path": {
"19": (isActive ? "icon-19.png" : "icon-19-deactivated.png"),
"38": (isActive ? "icon-38.png" : "icon-38-deactivated.png")
}
};
chrome.pageAction.setIcon(icon);
}
chrome.tabs.onUpdated.addListener(checkPage);
chrome.pageAction.onClicked.addListener(toggleExt);
chrome.runtime.onMessage.addListener(function(request, sender) {
updateIcon(sender.tab, request.active);
isActive = false;
});
}
main();