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: updated mockup Created July 14, 2015, 3:05 p.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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 this.disabled = false; 157 this.disabled = false;
149 } 158 }
150 }; 159 };
151 modules.filterClasses.Filter.fromText = function(text) 160 modules.filterClasses.Filter.fromText = function(text)
152 { 161 {
153 return new modules.filterClasses.Filter(text); 162 return new modules.filterClasses.Filter(text);
154 }; 163 };
155 164
156 modules.filterValidation = 165 modules.filterValidation =
157 { 166 {
158 FilterParsingError: function(type)
159 {
160 this.type = type;
161 },
162 parseFilter: function(text) 167 parseFilter: function(text)
163 { 168 {
164 if (text[0] == "[") 169
165 return {error: new modules.filterValidation.FilterParsingError("Error-oc curred")}; 170 if (params.filterError)
166 else 171 return {error: "Invalid filter"};
167 return {filter: modules.filterClasses.Filter.fromText(text)}; 172 return {filter: modules.filterClasses.Filter.fromText(text)};
168 }, 173 },
169 parseFilters: function(text) 174 parseFilters: function(text)
170 { 175 {
171 var lines = text.split("\n"); 176 if (params.filterError)
172 var filters = []; 177 return {errors: ["Invalid filter"]};
173 var errors = []; 178 return {filters:
174 179 text.split("\n").map(modules.filterClasses.Filter.fromText)};
175 for (var i = 0; i < lines.length; i++) 180 }
176 {
177 var parseResult = modules.filterValidation.parseFilter(lines[i]);
178 if (parseResult.error)
179 errors.push(parseResult.error);
180 else
181 filters.push(parseResult.filter);
182 }
183
184 return {filters: filters, errors: errors};
185 }
186 };
187 modules.filterValidation.FilterParsingError.prototype.toString = function()
188 {
189 return this.type;
190 }; 181 };
191 182
192 modules.synchronizer = { 183 modules.synchronizer = {
193 Synchronizer: {} 184 Synchronizer: {}
194 }; 185 };
195 186
196 modules.matcher = { 187 modules.matcher = {
197 defaultMatcher: { 188 defaultMatcher: {
198 matchesAny: function(url, requestType, docDomain, thirdParty) 189 matchesAny: function(url, requestType, docDomain, thirdParty)
199 { 190 {
200 var params = {blockedURLs: ""};
201 updateFromURL(params);
202 var blocked = params.blockedURLs.split(","); 191 var blocked = params.blockedURLs.split(",");
203 if (blocked.indexOf(url) >= 0) 192 if (blocked.indexOf(url) >= 0)
204 return new modules.filterClasses.BlockingFilter(); 193 return new modules.filterClasses.BlockingFilter();
205 else 194 else
206 return null; 195 return null;
207 } 196 }
208 } 197 }
209 }; 198 };
210 199
211 var notifierListeners = []; 200 var notifierListeners = [];
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", 270 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
282 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", 271 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
283 "https://easylist-downloads.adblockplus.org/fanboy-social.txt", 272 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
284 "~user~786254" 273 "~user~786254"
285 ]; 274 ];
286 var knownSubscriptions = Object.create(null); 275 var knownSubscriptions = Object.create(null);
287 for (var subscriptionUrl of subscriptions) 276 for (var subscriptionUrl of subscriptions)
288 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl); 277 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl);
289 var customSubscription = knownSubscriptions["~user~786254"]; 278 var customSubscription = knownSubscriptions["~user~786254"];
290 279
291 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; 280 global.seenDataCorruption = params.seenDataCorruption;
292 updateFromURL(issues); 281 global.filterlistsReinitialized = params.filterlistsReinitialized;
293 global.seenDataCorruption = issues.seenDataCorruption;
294 global.filterlistsReinitialized = issues.filterlistsReinitialized;
295 282
296 var events = {addSubscription: false}; 283 if (params.addSubscription)
297 updateFromURL(events);
298 if (events.addSubscription)
299 { 284 {
300 // 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
301 // so we'll post the message after one second 286 // so we'll post the message after one second
302 setTimeout(function() 287 setTimeout(function()
303 { 288 {
304 window.postMessage({ 289 window.postMessage({
305 type: "message", 290 type: "message",
306 payload: { 291 payload: {
307 title: "Custom subscription", 292 title: "Custom subscription",
308 url: "http://example.com/custom.txt", 293 url: "http://example.com/custom.txt",
309 type: "add-subscription" 294 type: "add-subscription"
310 } 295 }
311 }, "*"); 296 }, "*");
312 }, 1000); 297 }, 1000);
313 } 298 }
314 })(this); 299 })(this);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld