-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.js
104 lines (76 loc) · 3.02 KB
/
settings.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
var Settings = (function(){
var self = {};
self.bookmark_icon = (window.localStorage.getItem('toolbar_bookmark_icon'))
? window.localStorage.getItem('toolbar_bookmark_icon')
: 'default';
if (self.bookmark_icon === 'default') {
document.getElementById('bookmark_icon_def').checked = 'checked';
} else {
document.getElementById('bookmark_icon_favicon').checked = 'checked';
}
// display current value
self.bookmark_url = window.localStorage.getItem('toolbar_bookmark_url');
document.getElementById('bookmark_url').value = self.bookmark_url;
self.translate = function() {
document.title = chrome.i18n.getMessage('cfg_title');
// translating all i18n elements
var i18n = document.getElementsByClassName('i18n');
for (var i = 0, len = i18n.length; i < len; i++) {
var id = i18n[i].id;
var trans = chrome.i18n.getMessage(id);
if (trans) {
if (i18n[i].nodeName === 'SPAN' || i18n[i].nodeName === 'LABEL' || i18n[i].nodeName === 'A') {
i18n[i].innerHTML = trans;
continue;
}
if (i18n[i].nodeName === 'INPUT' || i18n[i].nodeName === 'BUTTON') {
i18n[i].value = trans;
continue;
}
console.warn('Don\'t know how to handle translation for '+i18n[i].nodeName);
} else {
console.warn('No translation for '+id);
}
}
};
// saving new value
self.save = function() {
var url = document.getElementById('bookmark_url').value;
if (url !== '') {
window.localStorage.getItem('toolbar_bookmark_icon');
// ask background process to update icon
chrome.extension.sendRequest({
action : 'save_bookmark',
bookmark_url : url,
bookmark_icon : self.bookmark_icon
});
}
};
self.reset_icon = function() {
chrome.extension.sendRequest({action: 'reset_icon'});
};
return {
setBookmarkIcon: function(val) {
self.bookmark_icon = val;
},
save: self.save,
translate: self.translate
};
}());
document.addEventListener('DOMContentLoaded', function() {
//document.querySelector('button').addEventListener('click', clickHandler);
// saving
document.getElementById('cfg_save').addEventListener('click', Settings.save);
// close
document.getElementById('cfg_close').addEventListener('click', function() {
window.close();
return false;
});
document.getElementById('bookmark_icon_favicon').addEventListener('click', function() {
Settings.setBookmarkIcon('favicon');
});
document.getElementById('bookmark_icon_def').addEventListener('click', function() {
Settings.setBookmarkIcon('default');
});
Settings.translate();
});