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

Side by Side Diff: background.js

Issue 29333819: Issue 2375 - Implement "Blocking lists" section in new options page (Closed)
Patch Set: Fixed the progress indicator and small fixes Created Feb. 4, 2016, 5:43 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 | « README.md ('k') | i18n.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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 18 matching lines...) Expand all
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 = { 34 var params = {
35 blockedURLs: "", 35 blockedURLs: "",
36 seenDataCorruption: false, 36 seenDataCorruption: false,
37 filterlistsReinitialized: false, 37 filterlistsReinitialized: false,
38 addSubscription: false, 38 addSubscription: false,
39 filterError: false 39 filterError: false,
40 downloadStatus: "synchronize_ok"
40 }; 41 };
41 updateFromURL(params); 42 updateFromURL(params);
42 43
43 var modules = {}; 44 var modules = {};
44 global.require = function(module) 45 global.require = function(module)
45 { 46 {
46 return modules[module]; 47 return modules[module];
47 }; 48 };
48 49
49 modules.utils = { 50 modules.utils = {
(...skipping 14 matching lines...) Expand all
64 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org /exceptionrules.txt" 65 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org /exceptionrules.txt"
65 } 66 }
66 }; 67 };
67 68
68 modules.subscriptionClasses = { 69 modules.subscriptionClasses = {
69 Subscription: function(url) 70 Subscription: function(url)
70 { 71 {
71 this.url = url; 72 this.url = url;
72 this.title = "Subscription " + url; 73 this.title = "Subscription " + url;
73 this.disabled = false; 74 this.disabled = false;
74 this.lastDownload = 1234; 75 this._lastDownload = 1234;
76 this.homepage = "https://easylist.adblockplus.org/";
77 this.downloadStatus = params.downloadStatus;
75 }, 78 },
76 79
77 SpecialSubscription: function(url) 80 SpecialSubscription: function(url)
78 { 81 {
79 this.url = url; 82 this.url = url;
80 this.disabled = false; 83 this.disabled = false;
81 this.filters = knownFilters.slice(); 84 this.filters = knownFilters.slice();
82 } 85 }
83 }; 86 };
84 modules.subscriptionClasses.Subscription.fromURL = function(url) 87 modules.subscriptionClasses.Subscription.fromURL = function(url)
85 { 88 {
89 if (url in knownSubscriptions)
90 return knownSubscriptions[url];
91
86 if (/^https?:\/\//.test(url)) 92 if (/^https?:\/\//.test(url))
87 return new modules.subscriptionClasses.Subscription(url); 93 return new modules.subscriptionClasses.Subscription(url);
88 else 94 else
89 return new modules.subscriptionClasses.SpecialSubscription(url); 95 return new modules.subscriptionClasses.SpecialSubscription(url);
90 }; 96 };
91 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription; 97 modules.subscriptionClasses.DownloadableSubscription = modules.subscriptionCla sses.Subscription;
92 98
99 modules.subscriptionClasses.Subscription.prototype =
100 {
101 get lastDownload()
102 {
103 return this._lastDownload;
104 },
105 set lastDownload(value)
106 {
107 this._lastDownload = value;
108 modules.filterNotifier.FilterNotifier.triggerListeners("subscription.lastD ownload", this);
109 }
110 };
111
93 modules.filterStorage = { 112 modules.filterStorage = {
94 FilterStorage: { 113 FilterStorage: {
95 get subscriptions() 114 get subscriptions()
96 { 115 {
97 var subscriptions = []; 116 var subscriptions = [];
98 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions) 117 for (var url in modules.filterStorage.FilterStorage.knownSubscriptions)
99 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]); 118 subscriptions.push(modules.filterStorage.FilterStorage.knownSubscripti ons[url]);
100 return subscriptions; 119 return subscriptions;
101 }, 120 },
102 121
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 return { 196 return {
178 filters: text.split("\n") 197 filters: text.split("\n")
179 .filter(function(filter) {return !!filter;}) 198 .filter(function(filter) {return !!filter;})
180 .map(modules.filterClasses.Filter.fromText), 199 .map(modules.filterClasses.Filter.fromText),
181 errors: [] 200 errors: []
182 }; 201 };
183 } 202 }
184 }; 203 };
185 204
186 modules.synchronizer = { 205 modules.synchronizer = {
187 Synchronizer: {} 206 Synchronizer: {
207 downloading: false,
Thomas Greiner 2016/02/04 20:23:46 Detail: Since this is a "private" property I'd sug
208 execute: function(subscription, manual)
209 {
210 subscription.lastDownload = 0;
211 modules.synchronizer.Synchronizer.downloading = true;
212 setTimeout(function()
213 {
214 modules.synchronizer.Synchronizer.downloading = false;
215 subscription.lastDownload = Date.now() / 1000;
216 }, 500);
217 },
218 isExecuting: function(url)
219 {
220 return modules.synchronizer.Synchronizer.downloading;
221 }
222 }
188 }; 223 };
189 224
190 modules.matcher = { 225 modules.matcher = {
191 defaultMatcher: { 226 defaultMatcher: {
192 matchesAny: function(url, requestType, docDomain, thirdParty) 227 matchesAny: function(url, requestType, docDomain, thirdParty)
193 { 228 {
194 var blocked = params.blockedURLs.split(","); 229 var blocked = params.blockedURLs.split(",");
195 if (blocked.indexOf(url) >= 0) 230 if (blocked.indexOf(url) >= 0)
196 return new modules.filterClasses.BlockingFilter(); 231 return new modules.filterClasses.BlockingFilter();
197 else 232 else
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 312
278 var subscriptions = [ 313 var subscriptions = [
279 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", 314 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt",
280 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", 315 "https://easylist-downloads.adblockplus.org/exceptionrules.txt",
281 "https://easylist-downloads.adblockplus.org/fanboy-social.txt", 316 "https://easylist-downloads.adblockplus.org/fanboy-social.txt",
282 "~user~786254" 317 "~user~786254"
283 ]; 318 ];
284 var knownSubscriptions = Object.create(null); 319 var knownSubscriptions = Object.create(null);
285 for (var subscriptionUrl of subscriptions) 320 for (var subscriptionUrl of subscriptions)
286 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl); 321 knownSubscriptions[subscriptionUrl] = modules.subscriptionClasses.Subscripti on.fromURL(subscriptionUrl);
322
Thomas Greiner 2016/02/04 20:23:45 Detail: This empty line has been added without tou
287 var customSubscription = knownSubscriptions["~user~786254"]; 323 var customSubscription = knownSubscriptions["~user~786254"];
288 324
289 global.seenDataCorruption = params.seenDataCorruption; 325 global.seenDataCorruption = params.seenDataCorruption;
290 global.filterlistsReinitialized = params.filterlistsReinitialized; 326 global.filterlistsReinitialized = params.filterlistsReinitialized;
291 327
292 if (params.addSubscription) 328 if (params.addSubscription)
293 { 329 {
294 // We don't know how long it will take for the page to fully load 330 // We don't know how long it will take for the page to fully load
295 // so we'll post the message after one second 331 // so we'll post the message after one second
296 setTimeout(function() 332 setTimeout(function()
297 { 333 {
298 window.postMessage({ 334 window.postMessage({
299 type: "message", 335 type: "message",
300 payload: { 336 payload: {
301 title: "Custom subscription", 337 title: "Custom subscription",
302 url: "http://example.com/custom.txt", 338 url: "http://example.com/custom.txt",
303 type: "add-subscription" 339 type: "add-subscription"
304 } 340 }
305 }, "*"); 341 }, "*");
306 }, 1000); 342 }, 1000);
307 } 343 }
308 })(this); 344 })(this);
OLDNEW
« no previous file with comments | « README.md ('k') | i18n.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld