forked from Spiderpowa/TJDict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
44 lines (41 loc) · 1.68 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
(function(){
DEFAULT_OPTIONS = {
order: [],
open_method: 'popup',
close_method: 'auto',
hold_feature: false
}
for(var i in DICTIONARIES){
DEFAULT_OPTIONS[i] = true;
DEFAULT_OPTIONS.order.push(i);
}
// 顯示字典
for(var i in DICTIONARIES)
$('#dict_checkboxes').append('<div data-id="' + i + '" class="checkbox"><span class="glyphicon glyphicon-resize-vertical"></span><label><input id="' + i + '" name="' + i + '" type="checkbox"> ' + DICTIONARIES[i].title + '(' + DICTIONARIES[i].desc + ')</label></div>');
// 字典可排序
var sortableDict = new Sortable(document.getElementById('dict_checkboxes'));
// Storage BEGIN
function save_options() {
options = {};
for(var i in DICTIONARIES) options[i] = document.getElementById(i).checked;
options.order = sortableDict.toArray();
options.open_method = $('input[name=open_method]:checked').val();
options.close_method = $('input[name=close_method]:checked').val();
options.hold_feature = $('input[name=hold_feature]').prop('checked');
chrome.storage.sync.set(options, function() {
$('#modal_setting').modal('hide');
});
}
function restore_options() {
chrome.storage.sync.get(DEFAULT_OPTIONS, function(items){
$('input[name=open_method][value="' + items.open_method +'"]').prop('checked', true);
$('input[name=close_method][value="' + items.close_method +'"]').prop('checked', true);
$('input[name=hold_feature]').prop('checked', items.hold_feature);
for(var i in DICTIONARIES) document.getElementById(i).checked = items[i];
sortableDict.sort(items.order);
});
}
restore_options();
$('#save').click(save_options);
// Storage END
})();