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,82 @@ |
}; |
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(); |
+ 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); |
+ if (!messages) |
+ { |
+ console.error("Failed to load messages for locale " |
+ + (locale ? locale : "default")); |
+ return; |
+ } |
+ |
+ for (var i in messages) |
+ i18nMessages[i] = messages[i]; |
+} |
+ |
+function loadI18nMessages() |
+{ |
+ i18nMessages = {}; |
+ |
+ // Could be parsed from config.xml |
+ var defaultLocale = "en"; |
+ |
+ if (locale !== defaultLocale) |
+ loadMessagesForLocale(defaultLocale); |
+ |
+ loadMessagesForLocale(); |
+} |
+ |
+setDefaultOptions(); |
+createToolbarButton(); |
+refreshToolbarButton(); |
+loadI18nMessages(); |