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