-
Notifications
You must be signed in to change notification settings - Fork 4
/
options.js
57 lines (42 loc) · 1.76 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
function $(id) {
return document.getElementById(id);
}
function $$(classname) {
var nodeList = document.getElementsByClassName(classname);
var elts = [];
for (var i = 0; i < nodeList.length; i++)
elts.push(nodeList[i]);
return elts;
}
function lines(s) { return s ? s.split('\n') : []; }
function clamp(n, lo, hi) { return Math.min(hi, Math.max(lo, n)); }
function rows(n) { return clamp(n, 4, 40); }
function init() {
$('altIsMeta').checked = config.get('altIsMeta');
$$('file').forEach(function(t) {
if (config.get('bindingFiles').indexOf(t.value) !== -1)
t.checked = true;
});
$('urlEnabled').checked = config.get('urlEnabled');
$('bindingUrl').value = config.get('bindingUrl');
$('bindingText').value = config.get('bindingText');
$('bindingText').rows = rows(lines(config.get('bindingText')).length)
$('blacklist').value = config.get('blacklist').join('\n');
$('blacklist').rows = rows(config.get('blacklist').length);
$('username').value = config.get('username');
$('password').value = config.get('password');
}
function save() {
config.set('altIsMeta', $('altIsMeta').checked);
var isChecked = function(t) { return t.checked; };
var getValue = function(t) { return t.value; };
config.set('bindingFiles', $$('file').filter(isChecked).map(getValue));
config.set('urlEnabled', $('urlEnabled').checked);
config.set('bindingUrl', $('bindingUrl').value);
config.set('bindingText', $('bindingText').value);
config.set('blacklist', lines($('blacklist').value));
config.set('username', $('username').value);
config.set('password', $('password').value);
var reloadPort = chrome.extension.connect({name: 'reloadBindings'});
reloadPort.postMessage(null);
}