forked from Gachl/Virtual-Hosts-Chrome-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
50 lines (39 loc) · 1.36 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
var domain,
ip,
enabled,
background;
var loadHandler = function() {
// assign elements to variables for future references
domain = document.querySelector('#vhost_domain');
ip = document.querySelector('#vhost_ip');
enabled = document.querySelector('#vhost_enable');
background = chrome.extension.getBackgroundPage();
// add a listener to each input and set the value from the background
domain.addEventListener("keyup", updateHandler, false);
domain.value = background.settings.domain;
ip.addEventListener("keyup", updateHandler, false);
ip.value = background.settings.ip;
enabled.addEventListener("change", updateHandler, false);
enabled.checked = background.settings.enabled;
updateIcons();
};
var updateIcons = function() {
chrome.browserAction.setIcon({path: (background.settings.enabled ? 'enabled' : 'disabled') + '.png'});
};
var updateHandler = function(e)
{
var settings = {
'domain': domain.value,
'ip': ip.value,
'enabled': enabled.checked
};
// set the background settings
background.settings.domain = settings.domain;
background.settings.ip = settings.ip;
background.settings.enabled = settings.enabled;
updateIcons();
// persist settings
chrome.storage.sync.set(settings);
};
// init
document.addEventListener('DOMContentLoaded', loadHandler);