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 addSubscription querystring parameter for testing Created Jan. 30, 2015, 6:06 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') | ext/background.js » ('j') | ext/background.js » ('J')
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) {
Felix Dahlke 2015/05/28 20:35:41 Nit: Opening brace on the next line?
Thomas Greiner 2015/06/08 16:12:43 Done.
+ 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)
Felix Dahlke 2015/05/28 20:35:41 Can we do something less complex here? Took a whil
Thomas Greiner 2015/06/08 16:12:43 Done.
+ {
+ obj[subscription] = modules.subscriptionClasses.Subscription.fromURL(subscription);
+ return obj;
+ }, Object.create(null));
+
+ Object.defineProperty(modules.filterStorage.FilterStorage, "knownSubscriptions", {
Felix Dahlke 2015/05/28 20:35:41 Nit: Opening brace on the next line?
Thomas Greiner 2015/06/08 16:12:43 Done.
+ 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"];
Felix Dahlke 2015/05/28 20:35:41 Seeing this used a few times - how about a "consta
Thomas Greiner 2015/06/08 16:12:43 Done.
+ 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",
Felix Dahlke 2015/05/28 20:35:41 Shouldn't this be `addonName`?
Thomas Greiner 2015/06/08 16:12:43 Done. Thanks for pointing out this inconsistency.
+ addonVersion: "2.6.7"
};
updateFromURL(modules.info);
@@ -176,4 +244,23 @@
updateFromURL(issues);
global.seenDataCorruption = issues.seenDataCorruption;
global.filterlistsReinitialized = issues.filterlistsReinitialized;
+
+ var events = {addSubscription: false};
+ updateFromURL(events);
+ if (events.addSubscription)
+ {
+ // We don't know how long it will take for the page to fully load
+ // so we'll post the message after one second
+ setTimeout(function()
+ {
+ window.postMessage({
+ type: "message",
+ payload: {
+ title: "Custom subscription",
+ url: "http://example.com/custom.txt",
+ type: "add-subscription"
+ }
+ }, "*");
+ }, 1000);
+ }
})(this);
« no previous file with comments | « README.md ('k') | ext/background.js » ('j') | ext/background.js » ('J')

Powered by Google App Engine
This is Rietveld