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 EventEmitter() |
| 21 { |
| 22 this._listeners = Object.create(null); |
| 23 } |
| 24 EventEmitter.prototype = { |
| 25 on: function(name, listener) |
| 26 { |
| 27 if (name in this._listeners) |
| 28 this._listeners[name].push(listener); |
| 29 else |
| 30 this._listeners[name] = [listener]; |
| 31 }, |
| 32 off: function(name, listener) |
| 33 { |
| 34 var listeners = this._listeners[name]; |
| 35 if (listeners) |
| 36 { |
| 37 var idx = listeners.indexOf(listener); |
| 38 if (idx != -1) |
| 39 listeners.splice(idx, 1); |
| 40 } |
| 41 }, |
| 42 emit: function(name) |
| 43 { |
| 44 var listeners = this._listeners[name]; |
| 45 if (listeners) |
| 46 { |
| 47 for (var i = 0; i < listeners.length; i++) |
| 48 listeners[i].apply(null, Array.prototype.slice.call(arguments, 1)); |
| 49 } |
| 50 } |
| 51 }; |
| 52 |
20 function Notifier() | 53 function Notifier() |
21 { | 54 { |
22 this._listeners = []; | 55 this._eventEmitter = new EventEmitter(); |
23 } | 56 } |
24 Notifier.prototype = { | 57 Notifier.prototype = { |
25 _listeners: null, | |
26 | |
27 addListener: function(listener) | 58 addListener: function(listener) |
28 { | 59 { |
29 if (this._listeners.indexOf(listener) < 0) | 60 var listeners = this._eventEmitter[""]; |
30 this._listeners.push(listener); | 61 if (!listeners || listener.indexOf(listener) == -1) |
| 62 this._eventEmitter.on("", listener); |
31 }, | 63 }, |
32 | |
33 removeListener: function(listener) | 64 removeListener: function(listener) |
34 { | 65 { |
35 var index = this._listeners.indexOf(listener); | 66 this._eventEmitter.off("", listener); |
36 if (index >= 0) | |
37 this._listeners.splice(index, 1); | |
38 }, | 67 }, |
39 | |
40 triggerListeners: function() | 68 triggerListeners: function() |
41 { | 69 { |
42 var args = Array.prototype.slice.apply(arguments); | 70 var args = Array.prototype.slice.apply(arguments); |
43 var listeners = this._listeners.slice(); | 71 args.unshift(""); |
44 for (var i = 0; i < listeners.length; i++) | 72 this._eventEmitter.emit.apply(this._eventEmitter, args); |
45 listeners[i].apply(null, args); | |
46 } | 73 } |
47 }; | 74 }; |
48 | 75 |
49 function updateFromURL(data) | 76 function updateFromURL(data) |
50 { | 77 { |
51 if (window.location.search) | 78 if (window.location.search) |
52 { | 79 { |
53 var params = window.location.search.substr(1).split("&"); | 80 var params = window.location.search.substr(1).split("&"); |
54 for (var i = 0; i < params.length; i++) | 81 for (var i = 0; i < params.length; i++) |
55 { | 82 { |
(...skipping 28 matching lines...) Expand all Loading... |
84 { | 111 { |
85 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin
k); | 112 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(lin
k); |
86 }, | 113 }, |
87 get appLocale() | 114 get appLocale() |
88 { | 115 { |
89 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); | 116 return parent.ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); |
90 } | 117 } |
91 } | 118 } |
92 }; | 119 }; |
93 | 120 |
94 modules.prefs = { | 121 modules.prefs = {Prefs: new EventEmitter()}; |
95 Prefs: { | |
96 onChanged: new Notifier() | |
97 } | |
98 }; | |
99 var prefs = { | 122 var prefs = { |
100 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [], | 123 notifications_ignoredcategories: (params.showNotificationUI) ? ["*"] : [], |
101 notifications_showui: params.showNotificationUI, | 124 notifications_showui: params.showNotificationUI, |
102 safari_contentblocker: false, | 125 safari_contentblocker: false, |
103 shouldShowBlockElementMenu: true, | 126 shouldShowBlockElementMenu: true, |
104 show_devtools_panel: true, | 127 show_devtools_panel: true, |
105 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc
eptionrules.txt" | 128 subscriptions_exceptionsurl: "https://easylist-downloads.adblockplus.org/exc
eptionrules.txt" |
106 }; | 129 }; |
107 Object.keys(prefs).forEach(function(key) | 130 Object.keys(prefs).forEach(function(key) |
108 { | 131 { |
109 Object.defineProperty(modules.prefs.Prefs, key, { | 132 Object.defineProperty(modules.prefs.Prefs, key, { |
110 get: function() | 133 get: function() |
111 { | 134 { |
112 return prefs[key]; | 135 return prefs[key]; |
113 }, | 136 }, |
114 set: function(value) | 137 set: function(value) |
115 { | 138 { |
116 prefs[key] = value; | 139 prefs[key] = value; |
117 modules.prefs.Prefs.onChanged.triggerListeners(key); | 140 modules.prefs.Prefs.emit(key); |
118 return prefs[key]; | |
119 } | 141 } |
120 }); | 142 }); |
121 }); | 143 }); |
122 | 144 |
123 modules.notification = { | 145 modules.notification = { |
124 Notification: { | 146 Notification: { |
125 toggleIgnoreCategory: function(category) | 147 toggleIgnoreCategory: function(category) |
126 { | 148 { |
127 var categories = prefs.notifications_ignoredcategories; | 149 var categories = prefs.notifications_ignoredcategories; |
128 var index = categories.indexOf(category); | 150 var index = categories.indexOf(category); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 492 |
471 if (params.safariContentBlocker) | 493 if (params.safariContentBlocker) |
472 { | 494 { |
473 global.safari = { | 495 global.safari = { |
474 extension: { | 496 extension: { |
475 setContentBlocker: function() {} | 497 setContentBlocker: function() {} |
476 } | 498 } |
477 }; | 499 }; |
478 } | 500 } |
479 })(this); | 501 })(this); |
OLD | NEW |