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 show_devtools_panel: true, |
| 105 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc
eptionrules.txt" |
| 106 }; |
| 107 Object.keys(prefs).forEach(function(key) |
| 108 { |
| 109 Object.defineProperty(modules.prefs.Prefs, key, { |
| 110 get: function() |
| 111 { |
| 112 return prefs[key]; |
| 113 }, |
| 114 set: function(value) |
| 115 { |
| 116 prefs[key] = value; |
| 117 modules.prefs.Prefs.onChanged.triggerListeners(key); |
| 118 return prefs[key]; |
| 119 } |
| 120 }); |
| 121 }); |
| 122 |
| 123 modules.notification = { |
| 124 Notification: { |
| 125 toggleIgnoreCategory: function(category) |
| 126 { |
| 127 var categories = prefs.notifications_ignoredcategories; |
| 128 var index = categories.indexOf(category); |
| 129 if (index == -1) |
| 130 categories.push(category); |
| 131 else |
| 132 categories.splice(index, 1); |
| 133 modules.prefs.Prefs.notifications_ignoredcategories = categories; |
| 134 } |
66 } | 135 } |
67 }; | 136 }; |
68 | 137 |
69 modules.subscriptionClasses = { | 138 modules.subscriptionClasses = { |
70 Subscription: function(url) | 139 Subscription: function(url) |
71 { | 140 { |
72 this.url = url; | 141 this.url = url; |
73 this.title = "Subscription " + url; | 142 this.title = "Subscription " + url; |
74 this.disabled = false; | 143 this.disabled = false; |
75 this._lastDownload = 1234; | 144 this._lastDownload = 1234; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 305 } |
237 } | 306 } |
238 }; | 307 }; |
239 | 308 |
240 modules.cssRules = { | 309 modules.cssRules = { |
241 CSSRules: { | 310 CSSRules: { |
242 getRulesForDomain: function(domain) { } | 311 getRulesForDomain: function(domain) { } |
243 } | 312 } |
244 }; | 313 }; |
245 | 314 |
246 var notifierListeners = []; | |
247 modules.filterNotifier = { | 315 modules.filterNotifier = { |
248 FilterNotifier: { | 316 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 }; | 317 }; |
271 | 318 |
272 modules.info = { | 319 modules.info = { |
273 platform: "gecko", | 320 platform: "gecko", |
274 platformVersion: "34.0", | 321 platformVersion: "34.0", |
275 application: "firefox", | 322 application: "firefox", |
276 applicationVersion: "34.0", | 323 applicationVersion: "34.0", |
277 addonName: "adblockplus", | 324 addonName: "adblockplus", |
278 addonVersion: "2.6.7" | 325 addonVersion: "2.6.7" |
279 }; | 326 }; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 docDomain: "example.com" | 459 docDomain: "example.com" |
413 }, | 460 }, |
414 filter: { | 461 filter: { |
415 text: "||example.com/some-annoying-popup$popup", | 462 text: "||example.com/some-annoying-popup$popup", |
416 whitelisted: false, | 463 whitelisted: false, |
417 userDefined: true, | 464 userDefined: true, |
418 subscription: null | 465 subscription: null |
419 } | 466 } |
420 }); | 467 }); |
421 }); | 468 }); |
| 469 |
| 470 if (params.safariContentBlocker) |
| 471 { |
| 472 global.safari = { |
| 473 extension: { |
| 474 setContentBlocker: function() {} |
| 475 } |
| 476 }; |
| 477 } |
422 })(this); | 478 })(this); |
OLD | NEW |