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(); |
| 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 if (!messages) |
| 206 { |
| 207 console.error("Failed to load messages for locale " |
| 208 + (locale ? locale : "default")); |
| 209 return; |
| 210 } |
| 211 |
| 212 for (var i in messages) |
| 213 i18nMessages[i] = messages[i]; |
| 214 } |
| 215 |
| 216 function loadI18nMessages() |
| 217 { |
| 218 i18nMessages = {}; |
| 219 |
| 220 // Could be parsed from config.xml |
| 221 var defaultLocale = "en"; |
| 222 |
| 223 if (locale !== defaultLocale) |
| 224 loadMessagesForLocale(defaultLocale); |
| 225 |
| 226 loadMessagesForLocale(); |
| 227 } |
| 228 |
| 229 setDefaultOptions(); |
| 230 createToolbarButton(); |
| 231 refreshToolbarButton(); |
| 232 loadI18nMessages(); |
OLD | NEW |