-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.js
182 lines (166 loc) · 5.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
var dragsort = ToolMan.dragsort();
var junkdrawer = ToolMan.junkdrawer();
var searchType = "web";
window.onload = function(){
i18n();
resetSearchOrder();
bindEvent();
}
function bindEvent() {
//navigation
document.getElementById("generalsearch").addEventListener("click", function() {showOptions('general');}, false);
document.getElementById("websearch").addEventListener("click", function() {showOptions('web');}, false);
document.getElementById("imagesearch").addEventListener("click", function() {showOptions('image');}, false);
document.getElementById("mapsearch").addEventListener("click", function() {showOptions('map');}, false);
document.getElementById("aboutsearch").addEventListener("click", function() {showOptions('about');}, false);
//setGeneralOption
document.getElementById("autoredirect").addEventListener("click", function() {setGeneralOption();}, false);
document.getElementById("homepage").addEventListener("click", function() {setGeneralOption();}, false);
document.getElementById("aboutsearch").addEventListener("click", function() {setGeneralOption();}, false);
//save and reset order
document.getElementById("applybtn").addEventListener("click", function() {saveSearchOrder();}, false);
document.getElementById("resetbtn").addEventListener("click", function() {resetSearchOrder();}, false);
}
function i18n(){
var map = [
"title", "WebSearch", "ImageSearch", "MapSearch", "AboutSearch",
"autoredirecttips", "homepagetips", "tryfixtips", "advanced",
"primayopt", "primary", "secondary", "savedtips", "features",
"f1", "f2", "author", "dragsort", "selisti18n", "searchRedirect"
];
var elem = null;
for(var i = 0, len = map.length; i < len; i++){
elem = document.getElementById(map[i]);
if(elem){
var msg = chrome.i18n.getMessage(map[i]);
if(msg){
elem.innerHTML = msg;
}
}
}
document.getElementById("applybtn").value = chrome.i18n.getMessage("apply");
document.getElementById("resetbtn").value = chrome.i18n.getMessage("reset");
}
function verticalOnly(item) {
item.toolManDragGroup.verticalOnly()
}
function showOptions(type){
searchType = type;
deselectTab();
showTab(type);
switch(type){
case "web":
case "image":
case "map":
showSEOptions(type);
break;
case "general":
showGeneral();
break;
case "about":
showAbout();
break;
}
}
function showGeneral(){
var content = document.getElementById("generalcontent");
content.style.display = "";
var bg = chrome.extension.getBackgroundPage();
document.getElementById("autoredirect").checked = bg.SEManager.general.redirect;
document.getElementById("tryfix").checked = bg.SEManager.general.tryfix;
document.getElementById("homepage").checked = bg.SEManager.general.homepage;
}
function showAbout(){
var content = document.getElementById("aboutcontent");
content.style.display = "";
}
function showSEOptions(type){
var content = document.getElementById("searchcontent");
content.style.display = "";
var bg = chrome.extension.getBackgroundPage();
var order = bg.SEManager.getSEOrder(searchType);
var primary = document.getElementById("imageOnlyTwo");
primary.checked = bg.SEManager.getPrimaryOptions(searchType);
var lists = document.getElementById("searchlists");
lists.innerHTML = "";
var template = [
"<input type=checkbox ",
"", //checked or not
"/><img class=\"arrow\" src=\"arrow.png\"><img class=\"seicon\" src=\"",
"", //image src
"\">",
"" //se name
]
for(var i = 0, len = order.length; i < len; i++){
if(bg.SEManager.isDisabledSearchEngine(order[i].name, searchType)) {
template[1] = "";
} else {
template[1] = "checked";
}
template[3] = order[i].icon;
template[5] = order[i].name;
var li = document.createElement("li");
li.id = order[i].name;
li.innerHTML = template.join("");
lists.appendChild(li);
}
dragsort.makeListSortable(document.getElementById("searchlists"),
verticalOnly, saveOrder)
}
function saveOrder(item) {
var group = item.toolManDragGroup
group.register('dragend', function() {
hideSaveTips();
})
}
function hideSaveTips(){
var elem = document.getElementById("savedtips");
elem.style.display = "none";
}
function showTab(type){
var id = type + "search";
var elem = document.getElementById(id);
if(elem){
elem.className = "selected";
}
}
function deselectTab(){
var ids = ["generalsearch", "websearch", "imagesearch", "mapsearch", "aboutsearch"];
for(var i = 0, len = ids.length; i < len; i++){
var elem = document.getElementById(ids[i]);
elem.className = "";
}
var contents = ["generalcontent", "searchcontent", "aboutcontent", "savedtips"];
for(var i = 0, len = contents.length; i < len; i++){
var elem = document.getElementById(contents[i]);
elem.style.display = "none";
}
}
function resetSearchOrder(){
showOptions(searchType);
}
function saveSearchOrder(){
var lists = document.getElementById("searchlists");
var orders = lists.getElementsByTagName("li");
var seOrder = "";
var disabledSE = "";
for(var i = 0, len= orders.length; i < len; i++){
seOrder = seOrder + orders[i].id + ";";
var checkBox = orders[i].getElementsByTagName("input");
if(checkBox && !checkBox[0].checked) {
disabledSE = disabledSE + orders[i].id + ";";
}
}
var primary = document.getElementById("imageOnlyTwo").checked;
var bg = chrome.extension.getBackgroundPage();
bg.SEManager.saveSEOrder(primary, seOrder, disabledSE, searchType);
var elem = document.getElementById("savedtips");
elem.style.display = "";
}
function setGeneralOption(){
var redirect = document.getElementById("autoredirect").checked;
var tryfix = document.getElementById("tryfix").checked;
var homepage = document.getElementById("homepage").checked;
var bg = chrome.extension.getBackgroundPage();
bg.SEManager.setGeneralOptions(redirect, homepage, tryfix);
}