-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
43 lines (38 loc) · 1.33 KB
/
popup.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
var snowConfig = {
checkBoxId: 'snow-switcher',
snowStatusTextId: 'snow-switcher-text'
}
function toggleSnowSwitcherText(checked) {
var textEl = document.getElementById(snowConfig.snowStatusTextId);
if (textEl) {
textEl.innerText = checked ? 'Snow is enabled' : 'Snow is disabled';
}
}
function init() {
var checkBoxEl = document.getElementById(snowConfig.checkBoxId);
if (!checkBoxEl) {
return;
}
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
handler: false
}, function(response) {
checkBoxEl.checked = response.snowEnable;
toggleSnowSwitcherText(response.snowEnable);
checkBoxEl.addEventListener('change', function (event) {
var checked = event.target.checked;
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
snowEnable: checked,
handler: true
}, function(response) {
if (response.success) {
toggleSnowSwitcherText(checked);
}
});
});
});
});
});
}
init();