-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoptions.js
133 lines (126 loc) · 5.08 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
window.addEventListener('load', function(e){
var bg = chrome.extension.getBackgroundPage();
Array.prototype.slice.call(document.querySelectorAll('input[type="checkbox"]')).forEach(function(elm) {
elm.checked = bg.config[elm.id];
elm.addEventListener('click', function(e){
bg.config[e.target.id] = e.target.checked;
chrome.extension.sendMessage({
action: 'config.save'
});
}, false);
});
Array.prototype.slice.call(document.querySelectorAll('input[type="range"]')).forEach(function(elm) {
elm.value = bg.config[elm.id];
var output = document.getElementById(elm.id + '_val');
output.textContent = elm.value;
elm.addEventListener('change', function(e){
bg.config[e.target.id] = e.target.value;
output.textContent = e.target.value;
chrome.extension.sendMessage({
action: 'config.save'
});
}, false);
});
var autoSaveControl = function(){
if (document.getElementById('AutoSave').checked) {
document.getElementById('AutoSaveTime').disabled = false;
document.getElementById('AutoSaveDupplicateClose').disabled = false;
} else {
document.getElementById('AutoSaveTime').disabled = true;
document.getElementById('AutoSaveDupplicateClose').disabled = true;
}
};
autoSaveControl();
document.getElementById('AutoSave').addEventListener('click', function(e) {
autoSaveControl();
}, false);
var AddExcludeURL = function(item, index) {
var li = document.createElement('li');
var input = document.createElement('input');
input.type = 'text';
input.className = 'url';
input.value = item;
input.addEventListener('input',function(e){
bg.config.ExcludeURLs[index] = input.value;
chrome.extension.sendMessage({
action: 'config.save'
});
}, false);
li.appendChild(input);
var del = document.createElement('button');
del.textContent = 'Del';
del.addEventListener('click',function(e){
li.parentNode.removeChild(li);
bg.config.ExcludeURLs = bg.config.ExcludeURLs.filter(function(item, i){
return (i != index);
});
chrome.extension.sendMessage({
action: 'config.save'
});
}, false);
li.appendChild(del);
list.appendChild(li);
};
var list = document.getElementById('ExcludeURLs');
var text = document.getElementById('ExcludeURL_text');
document.getElementById('ExcludeURL_add').addEventListener('click', function(e) {
var url = document.getElementById('ExcludeURL_text').value;
if (url) {
AddExcludeURL(text.value, bg.config.ExcludeURLs.length);
bg.config.ExcludeURLs.push(url);
chrome.extension.sendMessage({
action: 'config.save'
});
text.value = '';
}
}, false);
bg.config.ExcludeURLs.forEach(AddExcludeURL);
document.getElementById('ResetLinks').addEventListener('click', function(e) {
if (confirm('Are you sure you want to delete all of the saved links ?')) {
chrome.extension.sendMessage({
action: 'link.init'
});
}
}, false);
document.getElementById('ResetConfig').addEventListener('click', function(e) {
if (confirm('Are sure you want to delete this config ?')) {
chrome.extension.sendMessage({
action: 'config.init'
}, function(){
location.reload();
});
}
}, false);
(function L10N(){
var labels = document.querySelectorAll('label');
for (var i = 0; i < labels.length; i++){
var message = chrome.i18n.getMessage('option_label_' + labels[i].htmlFor);
if (message)
labels[i].innerHTML = message;
}
var buttons = document.querySelectorAll('input[type=button]');
for (var i = 0; i < buttons.length; i++){
var message = chrome.i18n.getMessage('option_button_' + buttons[i].id);
if (message)
buttons[i].value = message;
}
var tips = document.querySelectorAll('span.tips');
for (var i = 0; i < tips.length; i++){
var message = chrome.i18n.getMessage('option_' + tips[i].id);
if (message)
tips[i].innerHTML = message;
}
var titles = document.querySelectorAll('h2');
for (var i = 0; i < titles.length; i++){
var message = chrome.i18n.getMessage('option_title_' + titles[i].id);
if (message)
titles[i].innerHTML = message;
}
var legends = document.querySelectorAll('legend');
for (var i = 0; i < legends.length; i++){
var message = chrome.i18n.getMessage('option_legend_' + legends[i].id);
if (message)
legends[i].textContent = message;
}
})();
}, false);