Index: background.js |
=================================================================== |
--- a/background.js |
+++ b/background.js |
@@ -1,8 +1,12 @@ |
+var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscription; |
+var WhitelistFilter = require("filterClasses").WhitelistFilter; |
var FilterNotifier = require("filterNotifier").FilterNotifier; |
var FilterStorage = require("filterStorage").FilterStorage; |
+var Prefs = require("prefs").Prefs; |
var Synchronizer = require("synchronizer").Synchronizer; |
var Subscription = require("subscriptionClasses").Subscription; |
-var DownloadableSubscription = require("subscriptionClasses").DownloadableSubscription; |
+var SpecialSubscription = require("subscriptionClasses").SpecialSubscription; |
+var Utils = require("utils").Utils; |
var isFirstRun = false; |
FilterNotifier.addListener(function(action) |
@@ -19,6 +23,9 @@ |
} |
}); |
+var toolbarButton; |
+var i18nMessages; |
+ |
function importOldData() |
{ |
// TODO: Remove this once most people have the update |
@@ -144,3 +151,78 @@ |
}; |
request.send(null); |
} |
+ |
+function setDefaultOptions() |
+{ |
+ function defaultOptionValue(opt, val) |
+ { |
+ if(!(opt in localStorage)) |
+ localStorage[opt] = val; |
+ } |
+ |
+ defaultOptionValue("shouldShowIcon", "true"); |
+} |
+ |
+function createToolbarButton() |
+{ |
+ var properties = { |
+ disabled: false, |
+ title: "Adblock Plus", |
+ icon: "icons/abp-18.png" |
+ }; |
+ |
+ toolbarButton = opera.contexts.toolbar.createItem(properties); |
+} |
+ |
+function refreshToolbarButton() |
+{ |
+ var toolbar = opera.contexts.toolbar; |
+ if (localStorage["shouldShowIcon"] === "true") |
+ toolbar.addItem(toolbarButton); |
+ else |
+ toolbar.removeItem(toolbarButton); |
+} |
+ |
+function getJson(url) |
+{ |
+ var request = new XMLHttpRequest(); |
+ request.open("GET", url, false); |
+ request.responseType = "json"; |
+ 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.
|
+ return request.response; |
+} |
+ |
+function loadMessagesForLocale(locale) |
+{ |
+ var messagesFileName = "messages.json"; |
+ var messagesPath; |
+ if (locale) |
+ messagesPath = "locales/" + locale + "/" + messagesFileName; |
+ else |
+ messagesPath = messagesFileName; |
+ |
+ var messages = getJson(messagesPath); |
+ for (var i in messages) |
+ i18nMessages[i] = messages[i]; |
+} |
+ |
+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.
|
+{ |
+ i18nMessages = {}; |
+ |
+ 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
|
+ 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
|
+ |
+ if (baseLocale !== language) |
+ loadMessagesForLocale(baseLocale); |
+ |
+ 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
|
+ loadMessagesForLocale(language); |
+ |
+ 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
|
+} |
+ |
+setDefaultOptions(); |
+createToolbarButton(); |
+refreshToolbarButton(); |
+loadI18nMessages(); |