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

Side by Side Diff: background.js

Issue 4864767881641984: Issue 1528 - Implemented backend for general tab of new options page (Closed)
Patch Set: Fixed filter management in background.js Created Jan. 27, 2015, 12:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | messageResponder.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 16 matching lines...) Expand all
27 var parts = params[i].split("=", 2); 27 var parts = params[i].split("=", 2);
28 if (parts.length == 2 && parts[0] in data) 28 if (parts.length == 2 && parts[0] in data)
29 data[parts[0]] = decodeURIComponent(parts[1]); 29 data[parts[0]] = decodeURIComponent(parts[1]);
30 } 30 }
31 } 31 }
32 } 32 }
33 33
34 var subscriptions =[ 34 var subscriptions =[
35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", 35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", 36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" 37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
38 "~user~786254"
39 ];
40 var filters = [
41 "@@||alternate.de^$document",
42 "@@||der.postillion.com^$document",
43 "@@||taz.de^$document",
44 "@@||amazon.de^$document"
38 ]; 45 ];
39 46
40 var modules = {}; 47 var modules = {};
41 global.require = function(module) 48 global.require = function(module)
42 { 49 {
43 return modules[module]; 50 return modules[module];
44 }; 51 };
45 52
46 modules.utils = { 53 modules.utils = {
47 Utils: { 54 Utils: {
48 getDocLink: function(link) 55 getDocLink: function(link)
49 { 56 {
50 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin k); 57 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin k);
51 } 58 }
52 } 59 }
53 }; 60 };
54 61
62 modules.prefs = {
63 Prefs: {
64 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org /exceptionrules.txt"
65 }
66 }
67
55 modules.subscriptionClasses = { 68 modules.subscriptionClasses = {
56 Subscription: function(url) 69 Subscription: function(url)
57 { 70 {
58 this.url = url; 71 this.url = url;
59 this.title = "Subscription " + url; 72 this.title = "Subscription " + url;
60 this.disabled = false; 73 this.disabled = false;
61 this.lastDownload = 1234; 74 this.lastDownload = 1234;
62 }, 75 },
63 76
64 SpecialSubscription: function() {} 77 SpecialSubscription: function(url) {
78 this.url = url;
79 this.disabled = false;
80 this.filters = filters.map(modules.filterClasses.Filter.fromText);
81 }
65 }; 82 };
66 modules.subscriptionClasses.Subscription.fromURL = function(url) 83 modules.subscriptionClasses.Subscription.fromURL = function(url)
67 { 84 {
68 return new modules.subscriptionClasses.Subscription(url); 85 if (/^https?:\/\//.test(url))
86 return new modules.subscriptionClasses.Subscription(url);
87 else
88 return new modules.subscriptionClasses.SpecialSubscription(url);
69 }; 89 };
70 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription; 90 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription;
71 91
72 modules.filterStorage = { 92 modules.filterStorage = {
73 FilterStorage: { 93 FilterStorage: {
74 get subscriptions() 94 get subscriptions()
75 { 95 {
76 return subscriptions.map(modules.subscriptionClasses.Subscription.fromUR L); 96 var subscriptions = [];
97 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions)
98 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]);
99 return subscriptions;
77 }, 100 },
78 101
79 get knownSubscriptions() 102 get knownSubscriptions()
80 { 103 {
81 var result = {}; 104 subscriptions = subscriptions.reduce(function(obj, subscription)
82 for (var i = 0; i < subscriptions.length; i++) 105 {
83 result[subscriptions[i]] = modules.subscriptionClasses.Subscription.fr omURL(subscriptions[i]); 106 obj[subscription] = modules.subscriptionClasses.Subscription.fromURL(s ubscription);
84 return result; 107 return obj;
108 }, Object.create(null));
109
110 Object.defineProperty(modules.filterStorage.FilterStorage, "knownSubscri ptions", {
111 get: function()
112 {
113 return subscriptions;
114 }
115 });
116
117 return modules.filterStorage.FilterStorage.knownSubscriptions;
85 }, 118 },
86 119
87 addSubscription: function(subscription) 120 addSubscription: function(subscription)
88 { 121 {
89 var index = subscriptions.indexOf(subscription.url); 122 if (!(subscription.url in modules.filterStorage.FilterStorage.knownSubsc riptions))
90 if (index < 0)
91 { 123 {
92 subscriptions.push(subscription.url); 124 subscriptions[subscription.url] = modules.subscriptionClasses.Subscrip tion.fromURL(subscription.url);
93 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a dded", subscription); 125 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.a dded", subscription);
94 } 126 }
95 }, 127 },
96 128
97 removeSubscription: function(subscription) 129 removeSubscription: function(subscription)
98 { 130 {
99 var index = subscriptions.indexOf(subscription.url); 131 if (subscription.url in modules.filterStorage.FilterStorage.knownSubscri ptions)
100 if (index >= 0)
101 { 132 {
102 subscriptions.splice(index, 1); 133 delete subscriptions[subscription.url];
103 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r emoved", subscription); 134 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.r emoved", subscription);
104 } 135 }
136 },
137
138 addFilter: function(filter)
139 {
140 var subscription = modules.filterStorage.FilterStorage.knownSubscription s["~user~786254"];
141 for (var i = 0; i < subscription.filters.length; i++)
142 {
143 if (subscription.filters[i].text == filter.text)
144 return;
145 }
146 subscription.filters.push(filter);
147 modules.filterNotifier.FilterNotifier.triggerListeners("filter.added", f ilter);
148 },
149
150 removeFilter: function(filter)
151 {
152 var subscription = modules.filterStorage.FilterStorage.knownSubscription s["~user~786254"];
153 for (var i = 0; i < subscription.filters.length; i++)
154 {
155 if (subscription.filters[i].text == filter.text)
156 {
157 subscription.filters.splice(i, 1);
158 modules.filterNotifier.FilterNotifier.triggerListeners("filter.remov ed", filter);
159 return;
160 }
161 }
105 } 162 }
106 } 163 }
107 }; 164 };
108 165
109 modules.filterClasses = { 166 modules.filterClasses = {
110 BlockingFilter: function() {} 167 BlockingFilter: function() {},
168 Filter: function(text)
169 {
170 this.text = text;
171 this.disabled = false;
172 }
173 };
174 modules.filterClasses.Filter.fromText = function(text)
175 {
176 return new modules.filterClasses.Filter(text);
111 }; 177 };
112 178
113 modules.synchronizer = { 179 modules.synchronizer = {
114 Synchronizer: {} 180 Synchronizer: {}
115 }; 181 };
116 182
117 modules.matcher = { 183 modules.matcher = {
118 defaultMatcher: { 184 defaultMatcher: {
119 matchesAny: function(url, requestType, docDomain, thirdParty) 185 matchesAny: function(url, requestType, docDomain, thirdParty)
120 { 186 {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 return parseFloat(v1) - parseFloat(v2); 236 return parseFloat(v1) - parseFloat(v2);
171 } 237 }
172 } 238 }
173 }; 239 };
174 240
175 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; 241 var issues = {seenDataCorruption: false, filterlistsReinitialized: false};
176 updateFromURL(issues); 242 updateFromURL(issues);
177 global.seenDataCorruption = issues.seenDataCorruption; 243 global.seenDataCorruption = issues.seenDataCorruption;
178 global.filterlistsReinitialized = issues.filterlistsReinitialized; 244 global.filterlistsReinitialized = issues.filterlistsReinitialized;
179 })(this); 245 })(this);
OLDNEW
« no previous file with comments | « no previous file | messageResponder.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld