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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 302 } |
235 } | 303 } |
236 }; | 304 }; |
237 | 305 |
238 modules.cssRules = { | 306 modules.cssRules = { |
239 CSSRules: { | 307 CSSRules: { |
240 getRulesForDomain: function(domain) { } | 308 getRulesForDomain: function(domain) { } |
241 } | 309 } |
242 }; | 310 }; |
243 | 311 |
244 var notifierListeners = []; | |
245 modules.filterNotifier = { | 312 modules.filterNotifier = { |
246 FilterNotifier: { | 313 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 }; | 314 }; |
269 | 315 |
270 modules.info = { | 316 modules.info = { |
271 platform: "gecko", | 317 platform: "gecko", |
272 platformVersion: "34.0", | 318 platformVersion: "34.0", |
273 application: "firefox", | 319 application: "firefox", |
274 applicationVersion: "34.0", | 320 applicationVersion: "34.0", |
275 addonName: "adblockplus", | 321 addonName: "adblockplus", |
276 addonVersion: "2.6.7" | 322 addonVersion: "2.6.7" |
277 }; | 323 }; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 docDomain: "example.com" | 456 docDomain: "example.com" |
411 }, | 457 }, |
412 filter: { | 458 filter: { |
413 text: "||example.com/some-annoying-popup$popup", | 459 text: "||example.com/some-annoying-popup$popup", |
414 whitelisted: false, | 460 whitelisted: false, |
415 userDefined: true, | 461 userDefined: true, |
416 subscription: null | 462 subscription: null |
417 } | 463 } |
418 }); | 464 }); |
419 }); | 465 }); |
| 466 |
| 467 if (params.safariContentBlocker) |
| 468 { |
| 469 global.safari = { |
| 470 extension: { |
| 471 setContentBlocker: function() {} |
| 472 } |
| 473 }; |
| 474 } |
420 })(this); | 475 })(this); |
OLD | NEW |