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

Delta Between Two Patch Sets: background.js

Issue 29488575: Issue 5384 - Introduced dedicated mobile options page (Closed)
Left Patch Set: Encapsulated mobile-options.js script Created July 18, 2017, 5:38 p.m.
Right Patch Set: Added ID constants Created Aug. 28, 2017, 2:51 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') | ext/background.js » ('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-2017 eyeo GmbH 3 * Copyright (C) 2006-present 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 } 97 }
98 }; 98 };
99 99
100 modules.prefs = {Prefs: new EventEmitter()}; 100 modules.prefs = {Prefs: new EventEmitter()};
101 let prefs = { 101 let prefs = {
102 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [], 102 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [],
103 notifications_showui: params.showNotificationUI, 103 notifications_showui: params.showNotificationUI,
104 shouldShowBlockElementMenu: true, 104 shouldShowBlockElementMenu: true,
105 show_devtools_panel: true, 105 show_devtools_panel: true,
106 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc eptionrules.txt" 106 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc eptionrules.txt",
107 subscriptions_exceptionsurl_privacy: "https://easylist-downloads.adblockplus .org/exceptionrules-privacy.txt"
107 }; 108 };
108 for (let key of Object.keys(prefs)) 109 for (let key of Object.keys(prefs))
109 { 110 {
110 Object.defineProperty(modules.prefs.Prefs, key, { 111 Object.defineProperty(modules.prefs.Prefs, key, {
111 get() 112 get()
112 { 113 {
113 return prefs[key]; 114 return prefs[key];
114 }, 115 },
115 set(value) 116 set(value)
116 { 117 {
(...skipping 11 matching lines...) Expand all
128 let index = categories.indexOf(category); 129 let index = categories.indexOf(category);
129 if (index == -1) 130 if (index == -1)
130 categories.push(category); 131 categories.push(category);
131 else 132 else
132 categories.splice(index, 1); 133 categories.splice(index, 1);
133 modules.prefs.Prefs.notifications_ignoredcategories = categories; 134 modules.prefs.Prefs.notifications_ignoredcategories = categories;
134 } 135 }
135 } 136 }
136 }; 137 };
137 138
139 let subscriptionServer = "https://easylist-downloads.adblockplus.org";
140 let subscriptionDetails = {
141 [`${subscriptionServer}/easylistgermany+easylist.txt`]: {
142 title: "EasyList Germany+EasyList",
143 installed: true
144 },
145 [`${subscriptionServer}/exceptionrules.txt`]: {
146 title: "Allow non-intrusive advertising",
147 installed: true
148 },
149 [`${subscriptionServer}/exceptionrules-privacy.txt`]: {
150 title: "Allow only nonintrusive ads that are privacy-friendly"
151 },
152 [`${subscriptionServer}/fanboy-social.txt`]: {
153 title: "Fanboy's Social Blocking List",
154 installed: true
155 },
156 [`${subscriptionServer}/antiadblockfilters.txt`]: {
157 title: "Adblock Warning Removal List",
158 installed: true,
159 disabled: true
160 },
161 "~user~786254": {
162 installed: true
163 }
164 };
165
138 function Subscription(url) 166 function Subscription(url)
139 { 167 {
140 this.url = url; 168 this.url = url;
141 this._disabled = false; 169 this._disabled = false;
142 this._lastDownload = 1234; 170 this._lastDownload = 1234;
143 this.homepage = "https://easylist.adblockplus.org/"; 171 this.homepage = "https://easylist.adblockplus.org/";
144 this.downloadStatus = params.downloadStatus; 172 this.downloadStatus = params.downloadStatus;
173
174 let details = subscriptionDetails[this.url];
175 if (details)
176 {
177 this.disabled = !!details.disabled;
178 this.title = details.title || "";
179 }
145 } 180 }
146 Subscription.prototype = 181 Subscription.prototype =
147 { 182 {
148 get disabled() 183 get disabled()
149 { 184 {
150 return this._disabled; 185 return this._disabled;
151 }, 186 },
152 set disabled(value) 187 set disabled(value)
153 { 188 {
154 this._disabled = value; 189 this._disabled = value;
155 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this); 190 modules.filterNotifier.FilterNotifier.emit("subscription.disabled", this);
156 }, 191 },
157 get lastDownload() 192 get lastDownload()
158 { 193 {
159 return this._lastDownload; 194 return this._lastDownload;
160 }, 195 },
161 set lastDownload(value) 196 set lastDownload(value)
162 { 197 {
163 this._lastDownload = value; 198 this._lastDownload = value;
164 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload", 199 modules.filterNotifier.FilterNotifier.emit("subscription.lastDownload",
165 this); 200 this);
166 } 201 }
167 }; 202 };
168 Subscription.fromURL = function(url) 203 Subscription.fromURL = function(url)
169 { 204 {
170 if (url in knownSubscriptions) 205 if (url in knownSubscriptions)
171 return knownSubscriptions[url]; 206 return knownSubscriptions[url];
172 207
173 if (/^https?:\/\//.test(url)) 208 if (/^https?:\/\//.test(url))
174 return new modules.subscriptionClasses.Subscription(url); 209 return new modules.subscriptionClasses.Subscription(url);
175 return new modules.subscriptionClasses.SpecialSubscription(url); 210 return new modules.subscriptionClasses.SpecialSubscription(url);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 244
210 addSubscription(subscription) 245 addSubscription(subscription)
211 { 246 {
212 let {fromURL} = Subscription; 247 let {fromURL} = Subscription;
213 let {FilterStorage} = modules.filterStorage; 248 let {FilterStorage} = modules.filterStorage;
214 249
215 if (!(subscription.url in FilterStorage.knownSubscriptions)) 250 if (!(subscription.url in FilterStorage.knownSubscriptions))
216 { 251 {
217 knownSubscriptions[subscription.url] = fromURL(subscription.url); 252 knownSubscriptions[subscription.url] = fromURL(subscription.url);
218 modules.filterNotifier.FilterNotifier.emit("subscription.added", 253 modules.filterNotifier.FilterNotifier.emit("subscription.added",
219 subscription); 254 subscription);
220 } 255 }
221 }, 256 },
222 257
223 removeSubscription(subscription) 258 removeSubscription(subscription)
224 { 259 {
225 let {FilterStorage} = modules.filterStorage; 260 let {FilterStorage} = modules.filterStorage;
226 261
227 if (subscription.url in FilterStorage.knownSubscriptions) 262 if (subscription.url in FilterStorage.knownSubscriptions)
228 { 263 {
229 delete knownSubscriptions[subscription.url]; 264 delete knownSubscriptions[subscription.url];
230 modules.filterNotifier.FilterNotifier.emit("subscription.removed", 265 modules.filterNotifier.FilterNotifier.emit("subscription.removed",
231 subscription); 266 subscription);
232 } 267 }
233 }, 268 },
234 269
235 addFilter(filter) 270 addFilter(filter)
236 { 271 {
237 for (let customFilter of customSubscription.filters) 272 for (let customFilter of customSubscription.filters)
238 { 273 {
239 if (customFilter.text == filter.text) 274 if (customFilter.text == filter.text)
240 return; 275 return;
241 } 276 }
242 customSubscription.filters.push(filter); 277 customSubscription.filters.push(filter);
243 modules.filterNotifier.FilterNotifier.emit("filter.added", filter); 278 modules.filterNotifier.FilterNotifier.emit("filter.added", filter);
244 }, 279 },
245 280
246 removeFilter(filter) 281 removeFilter(filter)
247 { 282 {
248 for (let i = 0; i < customSubscription.filters.length; i++) 283 for (let i = 0; i < customSubscription.filters.length; i++)
249 { 284 {
250 if (customSubscription.filters[i].text == filter.text) 285 if (customSubscription.filters[i].text == filter.text)
251 { 286 {
252 customSubscription.filters.splice(i, 1); 287 customSubscription.filters.splice(i, 1);
253 modules.filterNotifier.FilterNotifier.emit("filter.removed", 288 modules.filterNotifier.FilterNotifier.emit("filter.removed",
254 filter); 289 filter);
255 return; 290 return;
256 } 291 }
257 } 292 }
258 } 293 }
259 } 294 }
260 }; 295 };
261 296
262 function Filter(text) 297 function Filter(text)
263 { 298 {
264 this.text = text; 299 this.text = text;
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 "###Werbung_Sky", 467 "###Werbung_Sky",
433 "###Werbung_Wide", 468 "###Werbung_Wide",
434 "###__ligatus_placeholder__", 469 "###__ligatus_placeholder__",
435 "###ad-bereich1-08", 470 "###ad-bereich1-08",
436 "###ad-bereich1-superbanner", 471 "###ad-bereich1-superbanner",
437 "###ad-bereich2-08", 472 "###ad-bereich2-08",
438 "###ad-bereich2-skyscrapper" 473 "###ad-bereich2-skyscrapper"
439 ]; 474 ];
440 let knownFilters = filters.map(modules.filterClasses.Filter.fromText); 475 let knownFilters = filters.map(modules.filterClasses.Filter.fromText);
441 476
442 let subscriptionServer = "https://easylist-downloads.adblockplus.org";
443 let subscriptions = [
444 {
445 title: "EasyList Germany+EasyList",
446 url: `${subscriptionServer}/easylistgermany+easylist.txt`
447 },
448 {
449 title: "Allow non-intrusive advertising",
450 url: `${subscriptionServer}/exceptionrules.txt`
451 },
452 {
453 title: "Fanboy's Social Blocking List",
454 url: `${subscriptionServer}/fanboy-social.txt`
455 },
456 {
457 title: null,
458 url: "~user~786254"
459 }
460 ];
461 let knownSubscriptions = Object.create(null); 477 let knownSubscriptions = Object.create(null);
462 for (let {title, url} of subscriptions) 478 for (let url in subscriptionDetails)
463 { 479 {
464 let subscription = 480 if (!subscriptionDetails[url].installed)
481 continue;
482
483 knownSubscriptions[url] =
465 modules.subscriptionClasses.Subscription.fromURL(url); 484 modules.subscriptionClasses.Subscription.fromURL(url);
466 subscription.title = title;
467 knownSubscriptions[url] = subscription;
468 } 485 }
469 let customSubscription = knownSubscriptions["~user~786254"]; 486 let customSubscription = knownSubscriptions["~user~786254"];
470 487
471 if (params.addSubscription) 488 if (params.addSubscription)
472 { 489 {
473 // We don't know how long it will take for the page to fully load 490 // We don't know how long it will take for the page to fully load
474 // so we'll post the message after one second 491 // so we'll post the message after one second
475 setTimeout(() => 492 setTimeout(() =>
476 { 493 {
477 window.postMessage({ 494 window.postMessage({
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 }, 599 },
583 filter: { 600 filter: {
584 text: "||example.com/some-annoying-popup$popup", 601 text: "||example.com/some-annoying-popup$popup",
585 whitelisted: false, 602 whitelisted: false,
586 userDefined: true, 603 userDefined: true,
587 subscription: null 604 subscription: null
588 } 605 }
589 }); 606 });
590 }); 607 });
591 }()); 608 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld