-
Notifications
You must be signed in to change notification settings - Fork 5
/
background.js.firefox
42 lines (37 loc) · 992 Bytes
/
background.js.firefox
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
var currentTab;
var convertedTabs = new Set();
function updateIcon() {
chrome.browserAction.setIcon({
path: convertedTabs.has(currentTab) ? {
19: "icons/measuring-cup-pressed-19.png",
38: "icons/measuring-cup-pressed-38.png"
} : {
19: "icons/measuring-cup-19.png",
38: "icons/measuring-cup-38.png"
},
tabId: currentTab
});
}
function toggleConversion() {
if (convertedTabs.has(currentTab)) {
chrome.tabs.reload(currentTab);
convertedTabs.delete(currentTab);
} else {
chrome.tabs.executeScript(null, {file: "metric-cooking.js"});
convertedTabs.add(currentTab)
}
updateIcon();
}
function updateTab() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
if (tabs[0]) {
currentTab = tabs[0].id;
updateIcon();
}
});
}
chrome.tabs.onUpdated.addListener(updateTab);
chrome.tabs.onActivated.addListener(updateTab);
chrome.browserAction.onClicked.addListener(function(tab) {
toggleConversion();
});