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

Delta Between Two Patch Sets: background.js

Issue 29321198: Issue 2376 - Implement custom filters in new options page (Closed)
Left Patch Set: Created June 29, 2015, 11:21 a.m.
Right Patch Set: Nit fixes Created July 15, 2015, 2:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « README.md ('k') | locale/en-US/options.json » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 13 matching lines...) Expand all
24 var params = window.location.search.substr(1).split("&"); 24 var params = window.location.search.substr(1).split("&");
25 for (var i = 0; i < params.length; i++) 25 for (var i = 0; i < params.length; i++)
26 { 26 {
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 params = {
35 blockedURLs: "",
36 seenDataCorruption: false,
37 filterlistsReinitialized: false,
38 addSubscription: false,
39 filterError: false
40 };
41 updateFromURL(params);
42
34 var modules = {}; 43 var modules = {};
35 global.require = function(module) 44 global.require = function(module)
36 { 45 {
37 return modules[module]; 46 return modules[module];
38 }; 47 };
39 48
40 modules.utils = { 49 modules.utils = {
41 Utils: { 50 Utils: {
42 getDocLink: function(link) 51 getDocLink: function(link)
43 { 52 {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 148 }
140 } 149 }
141 }; 150 };
142 151
143 modules.filterClasses = { 152 modules.filterClasses = {
144 BlockingFilter: function() {}, 153 BlockingFilter: function() {},
145 Filter: function(text) 154 Filter: function(text)
146 { 155 {
147 this.text = text; 156 this.text = text;
148 this.disabled = false; 157 this.disabled = false;
149 }, 158 }
150 WhitelistFilter: function() {}
151 }; 159 };
152 modules.filterClasses.Filter.fromText = function(text) 160 modules.filterClasses.Filter.fromText = function(text)
153 { 161 {
154 return new modules.filterClasses.Filter(text); 162 return new modules.filterClasses.Filter(text);
155 }; 163 };
156 164
157 modules.filterValidation = 165 modules.filterValidation =
158 { 166 {
159 parseFilter: function(text) 167 parseFilter: function(text)
160 { 168 {
169
170 if (params.filterError)
171 return {error: "Invalid filter"};
161 return {filter: modules.filterClasses.Filter.fromText(text)}; 172 return {filter: modules.filterClasses.Filter.fromText(text)};
162 }, 173 },
163 parseFilters: function(text) 174 parseFilters: function(text)
164 { 175 {
165 var lines = text.split("\n"); 176 if (params.filterError)
166 var filters = []; 177 return {errors: ["Invalid filter"]};
167 var errors = []; 178 return {filters:
168 179 text.split("\n").map(modules.filterClasses.Filter.fromText)};
169 for (var i = 0; i < lines.length; i++)
170 filters.push(modules.filterValidation.parseFilter(lines[i]).filter);
171
172 return {filters: filters, errors: errors};
173 } 180 }
174 }; 181 };
175 182
176 modules.synchronizer = { 183 modules.synchronizer = {
177 Synchronizer: {} 184 Synchronizer: {}
178 }; 185 };
179 186
180 modules.matcher = { 187 modules.matcher = {
181 defaultMatcher: { 188 defaultMatcher: {
182 matchesAny: function(url, requestType, docDomain, thirdParty) 189 matchesAny: function(url, requestType, docDomain, thirdParty)
183 { 190 {
184 var params = {blockedURLs: ""};
185 updateFromURL(params);
186 var blocked = params.blockedURLs.split(","); 191 var blocked = params.blockedURLs.split(",");
187 if (blocked.indexOf(url) >= 0) 192 if (blocked.indexOf(url) >= 0)
188 return new modules.filterClasses.BlockingFilter(); 193 return new modules.filterClasses.BlockingFilter();
189 else 194 else
190 return null; 195 return null;
191 } 196 }
192 } 197 }
193 }; 198 };
194 199
195 var notifierListeners = []; 200 var notifierListeners = [];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 "###WerbungUntenLinks9_GesamtDIV", 258 "###WerbungUntenLinks9_GesamtDIV",
254 "###Werbung_Sky", 259 "###Werbung_Sky",
255 "###Werbung_Wide", 260 "###Werbung_Wide",
256 "###__ligatus_placeholder__", 261 "###__ligatus_placeholder__",
257 "###ad-bereich1-08", 262 "###ad-bereich1-08",
258 "###ad-bereich1-superbanner", 263 "###ad-bereich1-superbanner",
259 "###ad-bereich2-08", 264 "###ad-bereich2-08",
260 "###ad-bereich2-skyscrapper" 265 "###ad-bereich2-skyscrapper"
261 ]; 266 ];
262 var knownFilters = filters.map(modules.filterClasses.Filter.fromText); 267 var knownFilters = filters.map(modules.filterClasses.Filter.fromText);
263 global.WhitelistFilter = modules.filterClasses.WhitelistFilter;
Thomas Greiner 2015/06/30 09:23:26 This does not need to be in the global namespace.
saroyanm 2015/07/08 18:25:38 Done.
264 268
265 var subscriptions = [ 269 var subscriptions = [
266 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", 270 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
267 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", 271 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
268 "https://easylist-downloads.adblockplus.org/fanboy-social.txt", 272 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
269 "~user~786254" 273 "~user~786254"
270 ]; 274 ];
271 var knownSubscriptions = Object.create(null); 275 var knownSubscriptions = Object.create(null);
272 for (var subscriptionUrl of subscriptions) 276 for (var subscriptionUrl of subscriptions)
273 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl); 277 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl);
274 var customSubscription = knownSubscriptions["~user~786254"]; 278 var customSubscription = knownSubscriptions["~user~786254"];
275 279
276 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; 280 global.seenDataCorruption = params.seenDataCorruption;
277 updateFromURL(issues); 281 global.filterlistsReinitialized = params.filterlistsReinitialized;
278 global.seenDataCorruption = issues.seenDataCorruption;
279 global.filterlistsReinitialized = issues.filterlistsReinitialized;
280 282
281 var events = {addSubscription: false}; 283 if (params.addSubscription)
282 updateFromURL(events);
283 if (events.addSubscription)
284 { 284 {
285 // We don't know how long it will take for the page to fully load 285 // We don't know how long it will take for the page to fully load
286 // so we'll post the message after one second 286 // so we'll post the message after one second
287 setTimeout(function() 287 setTimeout(function()
288 { 288 {
289 window.postMessage({ 289 window.postMessage({
290 type: "message", 290 type: "message",
291 payload: { 291 payload: {
292 title: "Custom subscription", 292 title: "Custom subscription",
293 url: "http://example.com/custom.txt", 293 url: "http://example.com/custom.txt",
294 type: "add-subscription" 294 type: "add-subscription"
295 } 295 }
296 }, "*"); 296 }, "*");
297 }, 1000); 297 }, 1000);
298 } 298 }
299 })(this); 299 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld