-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoptions.js
83 lines (66 loc) · 2.46 KB
/
options.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
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/*
Grays out or [whatever the opposite of graying out is called] the option
field.
*/
function ghost(isDeactivated) {
options.style.color = isDeactivated ? 'graytext' : 'black';
}
window.addEventListener('load', function() {
// Initialize the option controls.
options.isActivated.checked = JSON.parse(localStorage.isActivated);
if (!options.isActivated.checked) { ghost(true); }
// Set the display activation and frequency.
options.isActivated.onchange = function() {
localStorage.isActivated = options.isActivated.checked;
ghost(!options.isActivated.checked);
};
document.getElementById('save').addEventListener('click',
save_options);
restore_options()
});
function save_options() {
var server = document.getElementById('server').value;
var username = document.getElementById('username').value;
var password = document.getElementById('password').value;
var zdserver = document.getElementById('zdserver').value;
var zdusername = document.getElementById('zdusername').value;
var zdpassword = document.getElementById('zdpassword').value;
chrome.storage.sync.set({
ns_server: server,
ns_username: username,
ns_password: password,
zd_server: zdserver,
zd_username: zdusername,
zd_password: zdpassword
}, function() {
// Update status to let user know options were saved.
var status = document.getElementById('status');
status.textContent = 'Options saved.';
setTimeout(function() {
status.textContent = '';
}, 750);
});
}
// Restores select box and checkbox state using the preferences
// stored in chrome.storage.
function restore_options() {
// Use default value color = 'red' and likesColor = true.
chrome.storage.sync.get({
ns_server: '',
ns_username: "",
ns_password: "",
zd_server: '',
zd_username: "",
zd_password: ""
}, function(items) {
document.getElementById('server').value = items.ns_server;
document.getElementById('username').value = items.ns_username;
document.getElementById('password').value = items.ns_password;
document.getElementById('zdserver').value = items.zd_server;
document.getElementById('zdusername').value = items.zd_username;
document.getElementById('zdpassword').value = items.zd_password;
});
}