-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpopup.js
70 lines (70 loc) · 2.61 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
window.onload=function()
{
let rad = document.getElementById('popupForm').zone;
for (var i = 0; i < rad.length; i++) {
rad[i].addEventListener('change', function(e) {
browser.runtime.sendMessage({ type: 'setZone', zone: e.target.id });
browser.runtime.sendMessage({ type: 'setZoneAutomatic', isZoneAutomatic: false });
window.close();
});
}
let sending = browser.runtime.sendMessage({type:'getZone'});
sending.then(
function(message)
{
console.log('Restoring zone visual state to '+message.zone);
document.getElementById(message.zone).checked = true;
},
function(error)
{
console.log('Error getting zone: '+error);
}
)
let autoBox = document.getElementById('popupForm').zoneAuto;
autoBox.addEventListener('change', function(e) {
browser.runtime.sendMessage({ type: 'setZoneAutomatic', isZoneAutomatic: e.target.checked });
window.close();
});
let automatic = browser.runtime.sendMessage({type:'getZoneAutomatic'});
automatic.then(
function(message)
{
console.log('Restoring zone visual state for automatic to '+message.isZoneAutomatic);
document.getElementById('isZoneAutomatic').checked = message.isZoneAutomatic;
},
function(error)
{
console.log('Error getting zone automatic: '+error);
}
);
let checkOnOff = document.getElementById('isOnOff');
checkOnOff.addEventListener('change', function(e) {
console.log('Setting on/off to '+e.target.checked);
browser.runtime.sendMessage({ type: 'setOnOff', onOff: e.target.checked ? 'on' : 'off' });
window.close();
})
let sendingOnOff = browser.runtime.sendMessage({type:'getOnOff'});
sendingOnOff.then(
function(message)
{
console.log('Restoring on/off state to '+message.onOff);
document.getElementById('isOnOff').checked = message.onOff=='on';
},
function(error)
{
console.log('Error getting onOff: '+error);
}
)
let sendingOnOffShown = browser.runtime.sendMessage({type:'getOnOffSwitchShown'});
sendingOnOffShown.then(
function(message)
{
console.log('Restoring on/off shown state to '+message.isOnOffSwitchShown);
document.getElementById('isOnOffSection').className = message.isOnOffSwitchShown ? 'switch_visible' : 'switch_hidden';
},
function(error)
{
console.log('Error getting onOffShown: '+error);
}
)
}