OLD | NEW |
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: { |
65 "subscriptions_exceptionsurl": "https://easylist-downloads.adblockplus.org
/exceptionrules.txt" | 96 onChanged: new Notifier() |
| 97 } |
| 98 }; |
| 99 var prefs = { |
| 100 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [], |
| 101 notifications_showui: params.showNotificationUI, |
| 102 safari_contentblocker: false, |
| 103 shouldShowBlockElementMenu: true, |
| 104 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc
eptionrules.txt" |
| 105 }; |
| 106 Object.keys(prefs).forEach(function(key) |
| 107 { |
| 108 Object.defineProperty(modules.prefs.Prefs, key, { |
| 109 get: function() |
| 110 { |
| 111 return prefs[key]; |
| 112 }, |
| 113 set: function(value) |
| 114 { |
| 115 prefs[key] = value; |
| 116 modules.prefs.Prefs.onChanged.triggerListeners(key); |
| 117 return prefs[key]; |
| 118 } |
| 119 }); |
| 120 }); |
| 121 |
| 122 modules.notification = { |
| 123 Notification: { |
| 124 toggleIgnoreCategory: function(category) |
| 125 { |
| 126 var categories = prefs.notifications_ignoredcategories; |
| 127 var index = categories.indexOf(category); |
| 128 if (index == -1) |
| 129 categories.push(category); |
| 130 else |
| 131 categories.splice(index, 1); |
| 132 modules.prefs.Prefs.notifications_ignoredcategories = categories; |
| 133 } |
66 } | 134 } |
67 }; | 135 }; |
68 | 136 |
69 modules.subscriptionClasses = { | 137 modules.subscriptionClasses = { |
70 Subscription: function(url) | 138 Subscription: function(url) |
71 { | 139 { |
72 this.url = url; | 140 this.url = url; |
73 this.title = "Subscription " + url; | 141 this.title = "Subscription " + url; |
74 this.disabled = false; | 142 this.disabled = false; |
75 this._lastDownload = 1234; | 143 this._lastDownload = 1234; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 304 } |
237 } | 305 } |
238 }; | 306 }; |
239 | 307 |
240 modules.cssRules = { | 308 modules.cssRules = { |
241 CSSRules: { | 309 CSSRules: { |
242 getRulesForDomain: function(domain) { } | 310 getRulesForDomain: function(domain) { } |
243 } | 311 } |
244 }; | 312 }; |
245 | 313 |
246 var notifierListeners = []; | |
247 modules.filterNotifier = { | 314 modules.filterNotifier = { |
248 FilterNotifier: { | 315 FilterNotifier: new Notifier() |
249 addListener: function(listener) | |
250 { | |
251 if (notifierListeners.indexOf(listener) < 0) | |
252 notifierListeners.push(listener); | |
253 }, | |
254 | |
255 removeListener: function(listener) | |
256 { | |
257 var index = notifierListeners.indexOf(listener); | |
258 if (index >= 0) | |
259 notifierListeners.splice(index, 1); | |
260 }, | |
261 | |
262 triggerListeners: function() | |
263 { | |
264 var args = Array.prototype.slice.apply(arguments); | |
265 var listeners = notifierListeners.slice(); | |
266 for (var i = 0; i < listeners.length; i++) | |
267 listeners[i].apply(null, args); | |
268 } | |
269 } | |
270 }; | 316 }; |
271 | 317 |
272 modules.info = { | 318 modules.info = { |
273 platform: "gecko", | 319 platform: "gecko", |
274 platformVersion: "34.0", | 320 platformVersion: "34.0", |
275 application: "firefox", | 321 application: "firefox", |
276 applicationVersion: "34.0", | 322 applicationVersion: "34.0", |
277 addonName: "adblockplus", | 323 addonName: "adblockplus", |
278 addonVersion: "2.6.7" | 324 addonVersion: "2.6.7" |
279 }; | 325 }; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 docDomain: "example.com" | 458 docDomain: "example.com" |
413 }, | 459 }, |
414 filter: { | 460 filter: { |
415 text: "||example.com/some-annoying-popup$popup", | 461 text: "||example.com/some-annoying-popup$popup", |
416 whitelisted: false, | 462 whitelisted: false, |
417 userDefined: true, | 463 userDefined: true, |
418 subscription: null | 464 subscription: null |
419 } | 465 } |
420 }); | 466 }); |
421 }); | 467 }); |
| 468 |
| 469 if (params.safariContentBlocker) |
| 470 { |
| 471 global.safari = { |
| 472 extension: { |
| 473 setContentBlocker: function() {} |
| 474 } |
| 475 }; |
| 476 } |
422 })(this); | 477 })(this); |
OLD | NEW |