Left: | ||
Right: |
OLD | NEW |
---|---|
1 var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscr iption; | |
2 var WhitelistFilter = require("filterClasses").WhitelistFilter; | |
1 var FilterNotifier = require("filterNotifier").FilterNotifier; | 3 var FilterNotifier = require("filterNotifier").FilterNotifier; |
2 var FilterStorage = require("filterStorage").FilterStorage; | 4 var FilterStorage = require("filterStorage").FilterStorage; |
5 var Prefs = require("prefs").Prefs; | |
3 var Synchronizer = require("synchronizer").Synchronizer; | 6 var Synchronizer = require("synchronizer").Synchronizer; |
4 var Subscription = require("subscriptionClasses").Subscription; | 7 var Subscription = require("subscriptionClasses").Subscription; |
5 var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscr iption; | 8 var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; |
9 var Utils = require("utils").Utils; | |
6 | 10 |
7 var isFirstRun = false; | 11 var isFirstRun = false; |
8 FilterNotifier.addListener(function(action) | 12 FilterNotifier.addListener(function(action) |
9 { | 13 { |
10 if (action == "load") | 14 if (action == "load") |
11 { | 15 { |
12 importOldData(); | 16 importOldData(); |
13 if (!window.localStorage.currentVersion) | 17 if (!window.localStorage.currentVersion) |
14 { | 18 { |
15 isFirstRun = true; | 19 isFirstRun = true; |
16 executeFirstRunActions(); | 20 executeFirstRunActions(); |
17 } | 21 } |
18 window.localStorage.currentVersion = require("info").addonVersion; | 22 window.localStorage.currentVersion = require("info").addonVersion; |
19 } | 23 } |
20 }); | 24 }); |
21 | 25 |
26 var toolbarButton; | |
27 var i18nMessages; | |
28 | |
22 function importOldData() | 29 function importOldData() |
23 { | 30 { |
24 // TODO: Remove this once most people have the update | 31 // TODO: Remove this once most people have the update |
25 if ("version" in widget.preferences) | 32 if ("version" in widget.preferences) |
26 { | 33 { |
27 var oldLists = { | 34 var oldLists = { |
28 "fanboy": "https://secure.fanboy.co.nz/fanboy-adblock.txt", | 35 "fanboy": "https://secure.fanboy.co.nz/fanboy-adblock.txt", |
29 "fanboy-ru": "https://secure.fanboy.co.nz/fanboy-russian.txt", | 36 "fanboy-ru": "https://secure.fanboy.co.nz/fanboy-russian.txt", |
30 "fanboy-es": "https://secure.fanboy.co.nz/fanboy-espanol.txt", | 37 "fanboy-es": "https://secure.fanboy.co.nz/fanboy-espanol.txt", |
31 "fanboy-ja": "https://secure.fanboy.co.nz/fanboy-japanese.txt", | 38 "fanboy-ja": "https://secure.fanboy.co.nz/fanboy-japanese.txt", |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 subscription.disabled = false; | 144 subscription.disabled = false; |
138 subscription.title = selectedItem.getAttribute("title"); | 145 subscription.title = selectedItem.getAttribute("title"); |
139 subscription.homepage = selectedItem.getAttribute("homepage"); | 146 subscription.homepage = selectedItem.getAttribute("homepage"); |
140 if (subscription instanceof DownloadableSubscription && !subscription.last Download) | 147 if (subscription instanceof DownloadableSubscription && !subscription.last Download) |
141 Synchronizer.execute(subscription); | 148 Synchronizer.execute(subscription); |
142 FilterStorage.addSubscription(subscription); | 149 FilterStorage.addSubscription(subscription); |
143 } | 150 } |
144 }; | 151 }; |
145 request.send(null); | 152 request.send(null); |
146 } | 153 } |
154 | |
155 function setDefaultOptions() | |
156 { | |
157 function defaultOptionValue(opt, val) | |
158 { | |
159 if(!(opt in localStorage)) | |
160 localStorage[opt] = val; | |
161 } | |
162 | |
163 defaultOptionValue("shouldShowIcon", "true"); | |
164 } | |
165 | |
166 function createToolbarButton() | |
167 { | |
168 var properties = { | |
169 disabled: false, | |
170 title: "Adblock Plus", | |
171 icon: "icons/abp-18.png" | |
172 }; | |
173 | |
174 toolbarButton = opera.contexts.toolbar.createItem(properties); | |
175 } | |
176 | |
177 function refreshToolbarButton() | |
178 { | |
179 var toolbar = opera.contexts.toolbar; | |
180 if (localStorage["shouldShowIcon"] === "true") | |
181 toolbar.addItem(toolbarButton); | |
182 else | |
183 toolbar.removeItem(toolbarButton); | |
184 } | |
185 | |
186 function getJson(url) | |
187 { | |
188 var request = new XMLHttpRequest(); | |
189 request.open("GET", url, false); | |
190 request.responseType = "json"; | |
191 request.send(); | |
Wladimir Palant
2012/10/17 10:17:14
What happens if the file doesn't exist? Won't this
Felix Dahlke
2012/10/18 08:08:46
Yes, you're right. Done.
| |
192 return request.response; | |
193 } | |
194 | |
195 function loadMessagesForLocale(locale) | |
196 { | |
197 var messagesFileName = "messages.json"; | |
198 var messagesPath; | |
199 if (locale) | |
200 messagesPath = "locales/" + locale + "/" + messagesFileName; | |
201 else | |
202 messagesPath = messagesFileName; | |
203 | |
204 var messages = getJson(messagesPath); | |
205 for (var i in messages) | |
206 i18nMessages[i] = messages[i]; | |
207 } | |
208 | |
209 function loadI18nMessages() | |
Wladimir Palant
2012/10/17 10:17:14
From the look of it, this function will never load
Felix Dahlke
2012/10/18 08:08:46
It does, that's the locale I use.
| |
210 { | |
211 i18nMessages = {}; | |
212 | |
213 var baseLocale = "en"; | |
Wladimir Palant
2012/10/17 10:17:14
Is there an easy way to get the default locale fro
Felix Dahlke
2012/10/18 08:08:46
Oh, didn't notice it was specified there. I have j
| |
214 var language = locale.split("-")[0]; | |
Wladimir Palant
2012/10/17 10:17:14
locale is undefined?
Felix Dahlke
2012/10/18 08:08:46
No, it's a global. It's defined in a locale-specif
| |
215 | |
216 if (baseLocale !== language) | |
217 loadMessagesForLocale(baseLocale); | |
218 | |
219 if (locale !== language) | |
Wladimir Palant
2012/10/17 10:17:14
What's the point of this check? Shouldn't we alway
Felix Dahlke
2012/10/18 08:08:46
"language" is just the language part, without the
| |
220 loadMessagesForLocale(language); | |
221 | |
222 loadMessagesForLocale(); | |
Wladimir Palant
2012/10/17 10:17:14
Locale-independent messages.json? Sounds pointless
Felix Dahlke
2012/10/18 08:08:46
messages.json exists once for each locale and is l
| |
223 } | |
224 | |
225 setDefaultOptions(); | |
226 createToolbarButton(); | |
227 refreshToolbarButton(); | |
228 loadI18nMessages(); | |
OLD | NEW |