forked from alecmev/trimless-gmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
62 lines (57 loc) · 2.2 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
chrome.storage.local.get(null, function(items) {
if (!items.hasOwnProperty('trimless-enabled')) {
items['trimless-enabled'] = true;
chrome.storage.local.set(items);
}
});
chrome.storage.sync.get(null, function(items) {
if (!items.hasOwnProperty('trimless-color-enabled')) {
items['trimless-color-enabled'] = true;
items['trimless-color-value'] = '#888888';
items['trimless-color-border'] = (
tinycolor(items['trimless-color-value'])
.lighten(27)
.toHexString()
.toUpperCase()
);
items['trimless-indentation-enabled'] = true;
items['trimless-indentation-value'] = 32;
items['trimless-reply-enabled'] = false;
chrome.storage.sync.set(items);
}
});
function updateIcon(tabId, isEnabled) {
chrome.pageAction.setIcon({ tabId: tabId, path: {
'19': 'images/icon-action' + (isEnabled ? '' : '-gray') + '-19.png',
'38': 'images/icon-action' + (isEnabled ? '' : '-gray') + '-38.png'
}});
chrome.pageAction.setTitle({ tabId: tabId,
title: (isEnabled ? 'Trimless is enabled' : 'Trimless is disabled')
});
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
chrome.tabs.sendMessage(tabId, true, function(data) {
if (data !== undefined && data.hasOwnProperty('trimless')) {
chrome.pageAction.show(tabId);
chrome.storage.local.get(null, function(items) {
updateIcon(tabId, items['trimless-enabled']);
});
}
});
});
chrome.pageAction.onClicked.addListener(function(tab) {
chrome.storage.local.get(null, function(items) {
items['trimless-enabled'] = !items['trimless-enabled'];
chrome.storage.local.set(items);
updateIcon(tab.id, items['trimless-enabled']);
});
});
chrome.runtime.onMessage.addListener(function(isEnabled, sender, sendResponse) {
updateIcon(sender.tab.id, isEnabled);
window.setTimeout(function() {
updateIcon(sender.tab.id, isEnabled);
}, 100);
window.setTimeout(function() {
updateIcon(sender.tab.id, isEnabled);
}, 200);
});