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

Side by Side Diff: background.js

Issue 29337729: Issue 2374 - Implemented Tweaks section in options page (Closed)
Patch Set: Created Feb. 25, 2016, 5:50 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
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
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 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 (function(global) 18 (function(global)
19 { 19 {
20 function Notifier()
21 {
22 this._listeners = [];
23 }
24 Notifier.prototype = {
25 _listeners: null,
26
27 addListener: function(listener)
28 {
29 if (this._listeners.indexOf(listener) < 0)
30 this._listeners.push(listener);
31 },
32
33 removeListener: function(listener)
34 {
35 var index = this._listeners.indexOf(listener);
36 if (index >= 0)
37 this._listeners.splice(index, 1);
38 },
39
40 triggerListeners: function()
41 {
42 var args = Array.prototype.slice.apply(arguments);
43 var listeners = this._listeners.slice();
44 for (var i = 0; i < listeners.length; i++)
45 listeners[i].apply(null, args);
46 }
47 };
48
20 function updateFromURL(data) 49 function updateFromURL(data)
21 { 50 {
22 if (window.location.search) 51 if (window.location.search)
23 { 52 {
24 var params = window.location.search.substr(1).split("&"); 53 var params = window.location.search.substr(1).split("&");
25 for (var i = 0; i < params.length; i++) 54 for (var i = 0; i < params.length; i++)
26 { 55 {
27 var parts = params[i].split("=", 2); 56 var parts = params[i].split("=", 2);
28 if (parts.length == 2 && parts[0] in data) 57 if (parts.length == 2 && parts[0] in data)
29 data[parts[0]] = decodeURIComponent(parts[1]); 58 data[parts[0]] = decodeURIComponent(parts[1]);
30 } 59 }
31 } 60 }
32 } 61 }
33 62
34 var params = { 63 var params = {
35 blockedURLs: "", 64 blockedURLs: "",
36 seenDataCorruption: false, 65 seenDataCorruption: false,
37 filterlistsReinitialized: false, 66 filterlistsReinitialized: false,
38 addSubscription: false, 67 addSubscription: false,
39 filterError: false, 68 filterError: false,
40 downloadStatus: "synchronize_ok" 69 downloadStatus: "synchronize_ok",
70 showNotificationUI: false,
71 safariContentBlocker: false
41 }; 72 };
42 updateFromURL(params); 73 updateFromURL(params);
43 74
44 var modules = {}; 75 var modules = {};
45 global.require = function(module) 76 global.require = function(module)
46 { 77 {
47 return modules[module]; 78 return modules[module];
48 }; 79 };
49 80
50 modules.utils = { 81 modules.utils = {
51 Utils: { 82 Utils: {
52 getDocLink: function(link) 83 getDocLink: function(link)
53 { 84 {
54 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin k); 85 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin k);
55 }, 86 },
56 get appLocale() 87 get appLocale()
57 { 88 {
58 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 89 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
59 } 90 }
60 } 91 }
61 }; 92 };
62 93
63 modules.prefs = { 94 modules.prefs = {
64 Prefs: { 95 Prefs: new Notifier()
65 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org /exceptionrules.txt" 96 };
97 var prefs = {
98 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [],
99 notifications_showui: params.showNotificationUI,
100 safari_contentblocker: false,
101 shouldShowBlockElementMenu: true,
102 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc eptionrules.txt"
103 };
104 Object.keys(prefs).forEach(function(key)
105 {
106 Object.defineProperty(modules.prefs.Prefs, key, {
107 get: function()
108 {
109 return prefs[key];
110 },
111 set: function(value)
112 {
113 prefs[key] = value;
114 modules.prefs.Prefs.triggerListeners(key);
115 return prefs[key];
116 }
117 });
118 });
119
120 modules.notification = {
121 Notification: {
122 toggleIgnoreCategory: function(category)
123 {
124 var categories = prefs.notifications_ignoredcategories;
125 var index = categories.indexOf(category);
126 if (index == -1)
127 categories.push(category);
128 else
129 categories.splice(index, 1);
130 modules.prefs.Prefs.notifications_ignoredcategories = categories;
131 }
66 } 132 }
67 }; 133 };
68 134
69 modules.subscriptionClasses = { 135 modules.subscriptionClasses = {
70 Subscription: function(url) 136 Subscription: function(url)
71 { 137 {
72 this.url = url; 138 this.url = url;
73 this.title = "Subscription " + url; 139 this.title = "Subscription " + url;
74 this.disabled = false; 140 this.disabled = false;
75 this._lastDownload = 1234; 141 this._lastDownload = 1234;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 300 }
235 } 301 }
236 }; 302 };
237 303
238 modules.cssRules = { 304 modules.cssRules = {
239 CSSRules: { 305 CSSRules: {
240 getRulesForDomain: function(domain) { } 306 getRulesForDomain: function(domain) { }
241 } 307 }
242 }; 308 };
243 309
244 var notifierListeners = [];
245 modules.filterNotifier = { 310 modules.filterNotifier = {
246 FilterNotifier: { 311 FilterNotifier: new Notifier()
247 addListener: function(listener)
248 {
249 if (notifierListeners.indexOf(listener) < 0)
250 notifierListeners.push(listener);
251 },
252
253 removeListener: function(listener)
254 {
255 var index = notifierListeners.indexOf(listener);
256 if (index >= 0)
257 notifierListeners.splice(index, 1);
258 },
259
260 triggerListeners: function()
261 {
262 var args = Array.prototype.slice.apply(arguments);
263 var listeners = notifierListeners.slice();
264 for (var i = 0; i < listeners.length; i++)
265 listeners[i].apply(null, args);
266 }
267 }
268 }; 312 };
269 313
270 modules.info = { 314 modules.info = {
271 platform: "gecko", 315 platform: "gecko",
272 platformVersion: "34.0", 316 platformVersion: "34.0",
273 application: "firefox", 317 application: "firefox",
274 applicationVersion: "34.0", 318 applicationVersion: "34.0",
275 addonName: "adblockplus", 319 addonName: "adblockplus",
276 addonVersion: "2.6.7" 320 addonVersion: "2.6.7"
277 }; 321 };
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 docDomain: "example.com" 454 docDomain: "example.com"
411 }, 455 },
412 filter: { 456 filter: {
413 text: "||example.com/some-annoying-popup$popup", 457 text: "||example.com/some-annoying-popup$popup",
414 whitelisted: false, 458 whitelisted: false,
415 userDefined: true, 459 userDefined: true,
416 subscription: null 460 subscription: null
417 } 461 }
418 }); 462 });
419 }); 463 });
464
465 if (params.safariContentBlocker)
466 {
467 global.safari = {
468 extension: {
469 setContentBlocker: function() {}
470 }
471 };
472 }
420 })(this); 473 })(this);
OLDNEW

Powered by Google App Engine
This is Rietveld