-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
28 lines (23 loc) · 1020 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
// Set Icon: manifest.json bug prevents using svg
// Overrides default in manifest.json
chrome.browserAction.setIcon({path: 'icon.svg'});
var badgeState = 0; // Matches margin_state in content.js
// Send message to content.js that toolbar icon has been clicked
chrome.browserAction.onClicked.addListener(function (){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// Add badge to icon for tab
if (badgeState == 0) {
chrome.browserAction.setBadgeText({text: "> <", tabId: tabs[0].id});
badgeState = 1;
} else if (badgeState == 1) {
chrome.browserAction.setBadgeText({text: "><", tabId: tabs[0].id});
badgeState = 2;
} else {
chrome.browserAction.setBadgeText({text: "", tabId: tabs[0].id});
badgeState = 0;
}
chrome.tabs.sendMessage(tabs[0].id, {backgroundClick: true}, function(response) {
console.log(response);
});
});
});