Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: background.js

Issue 4864767881641984: Issue 1528 - Implemented backend for general tab of new options page (Closed)
Patch Set: Added app.get/addonVersion and fixed app.listen/addSubscription Created Jan. 30, 2015, 4:35 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « README.md ('k') | messageResponder.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: background.js
===================================================================
--- a/background.js
+++ b/background.js
@@ -34,7 +34,14 @@
var subscriptions =[
"https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
"https://easylist-downloads.adblockplus.org/exceptionrules.txt",
- "https://easylist-downloads.adblockplus.org/fanboy-social.txt"
+ "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
+ "~user~786254"
+ ];
+ var filters = [
+ "@@||alternate.de^$document",
+ "@@||der.postillion.com^$document",
+ "@@||taz.de^$document",
+ "@@||amazon.de^$document"
];
var modules = {};
@@ -52,6 +59,12 @@
}
};
+ modules.prefs = {
+ Prefs: {
+ "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org/exceptionrules.txt"
+ }
+ }
+
modules.subscriptionClasses = {
Subscription: function(url)
{
@@ -61,11 +74,18 @@
this.lastDownload = 1234;
},
- SpecialSubscription: function() {}
+ SpecialSubscription: function(url) {
+ this.url = url;
+ this.disabled = false;
+ this.filters = filters.map(modules.filterClasses.Filter.fromText);
+ }
};
modules.subscriptionClasses.Subscription.fromURL = function(url)
{
- return new modules.subscriptionClasses.Subscription(url);
+ if (/^https?:\/\//.test(url))
+ return new modules.subscriptionClasses.Subscription(url);
+ else
+ return new modules.subscriptionClasses.SpecialSubscription(url);
};
modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionClasses.Subscription;
@@ -73,41 +93,87 @@
FilterStorage: {
get subscriptions()
{
- return subscriptions.map(modules.subscriptionClasses.Subscription.fromURL);
+ var subscriptions = [];
+ for (var url in modules.filterStorage.FilterStorage.knownSubscriptions)
+ subscriptions.push(modules.filterStorage.FilterStorage.knownSubscriptions[url]);
+ return subscriptions;
},
get knownSubscriptions()
{
- var result = {};
- for (var i = 0; i < subscriptions.length; i++)
- result[subscriptions[i]] = modules.subscriptionClasses.Subscription.fromURL(subscriptions[i]);
- return result;
+ subscriptions = subscriptions.reduce(function(obj, subscription)
+ {
+ obj[subscription] = modules.subscriptionClasses.Subscription.fromURL(subscription);
+ return obj;
+ }, Object.create(null));
+
+ Object.defineProperty(modules.filterStorage.FilterStorage, "knownSubscriptions", {
+ get: function()
+ {
+ return subscriptions;
+ }
+ });
+
+ return modules.filterStorage.FilterStorage.knownSubscriptions;
},
addSubscription: function(subscription)
{
- var index = subscriptions.indexOf(subscription.url);
- if (index < 0)
+ if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubscriptions))
{
- subscriptions.push(subscription.url);
+ subscriptions[subscription.url] = modules.subscriptionClasses.Subscription.fromURL(subscription.url);
modules.filterNotifier.FilterNotifier.triggerListeners("subscription.added", subscription);
}
},
removeSubscription: function(subscription)
{
- var index = subscriptions.indexOf(subscription.url);
- if (index >= 0)
+ if (subscription.url in modules.filterStorage.FilterStorage.knownSubscriptions)
{
- subscriptions.splice(index, 1);
+ delete subscriptions[subscription.url];
modules.filterNotifier.FilterNotifier.triggerListeners("subscription.removed", subscription);
}
+ },
+
+ addFilter: function(filter)
+ {
+ var subscription = modules.filterStorage.FilterStorage.knownSubscriptions["~user~786254"];
+ for (var i = 0; i < subscription.filters.length; i++)
+ {
+ if (subscription.filters[i].text == filter.text)
+ return;
+ }
+ subscription.filters.push(filter);
+ modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", filter);
+ },
+
+ removeFilter: function(filter)
+ {
+ var subscription = modules.filterStorage.FilterStorage.knownSubscriptions["~user~786254"];
+ for (var i = 0; i < subscription.filters.length; i++)
+ {
+ if (subscription.filters[i].text == filter.text)
+ {
+ subscription.filters.splice(i, 1);
+ modules.filterNotifier.FilterNotifier.triggerListeners("filter.removed", filter);
+ return;
+ }
+ }
}
}
};
modules.filterClasses = {
- BlockingFilter: function() {}
+ BlockingFilter: function() {},
+ Filter: function(text)
+ {
+ this.text = text;
+ this.disabled = false;
+ }
+ };
+ modules.filterClasses.Filter.fromText = function(text)
+ {
+ return new modules.filterClasses.Filter(text);
};
modules.synchronizer = {
@@ -159,7 +225,9 @@
platform: "gecko",
platformVersion: "34.0",
application: "firefox",
- applicationVersion: "34.0"
+ applicationVersion: "34.0",
+ addon: "adblockplus",
+ addonVersion: "2.6.7"
};
updateFromURL(modules.info);
« no previous file with comments | « README.md ('k') | messageResponder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld