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-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 */ | 76 */ |
77 applied: false, | 77 applied: false, |
78 | 78 |
79 /** | 79 /** |
80 * Called on module startup. | 80 * Called on module startup. |
81 */ | 81 */ |
82 init: function() | 82 init: function() |
83 { | 83 { |
84 Prefs.addListener(function(name) | 84 Prefs.addListener(function(name) |
85 { | 85 { |
86 if (name == "enabled") | 86 if (name == "enabled" || name == "element_hiding_enabled") |
87 ElemHide.apply(); | 87 ElemHide.apply(); |
88 }); | 88 }); |
89 onShutdown.add(function() | 89 onShutdown.add(function() |
90 { | 90 { |
91 ElemHide.unapply(); | 91 ElemHide.unapply(); |
92 }); | 92 }); |
93 | 93 |
94 let styleFile = IO.resolveFilePath(Prefs.data_directory); | 94 let styleFile = IO.resolveFilePath(Prefs.data_directory); |
95 styleFile.append("elemhide.css"); | 95 styleFile.append("elemhide.css"); |
96 styleURL = Services.io.newFileURI(styleFile).QueryInterface(Ci.nsIFileURL); | 96 styleURL = Services.io.newFileURI(styleFile).QueryInterface(Ci.nsIFileURL); |
(...skipping 11 matching lines...) Expand all Loading... |
108 ElemHide.isDirty = false; | 108 ElemHide.isDirty = false; |
109 ElemHide.unapply(); | 109 ElemHide.unapply(); |
110 }, | 110 }, |
111 | 111 |
112 /** | 112 /** |
113 * Add a new element hiding filter | 113 * Add a new element hiding filter |
114 * @param {ElemHideFilter} filter | 114 * @param {ElemHideFilter} filter |
115 */ | 115 */ |
116 add: function(filter) | 116 add: function(filter) |
117 { | 117 { |
| 118 if (!Prefs.element_hiding_enabled) |
| 119 return; |
| 120 |
118 if (filter instanceof ElemHideException) | 121 if (filter instanceof ElemHideException) |
119 { | 122 { |
120 if (filter.text in knownExceptions) | 123 if (filter.text in knownExceptions) |
121 return; | 124 return; |
122 | 125 |
123 let selector = filter.selector; | 126 let selector = filter.selector; |
124 if (!(selector in exceptions)) | 127 if (!(selector in exceptions)) |
125 exceptions[selector] = []; | 128 exceptions[selector] = []; |
126 exceptions[selector].push(filter); | 129 exceptions[selector].push(filter); |
127 knownExceptions[filter.text] = true; | 130 knownExceptions[filter.text] = true; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 * Generates stylesheet URL and applies it globally | 208 * Generates stylesheet URL and applies it globally |
206 */ | 209 */ |
207 apply: function() | 210 apply: function() |
208 { | 211 { |
209 if (this._applying) | 212 if (this._applying) |
210 { | 213 { |
211 this._needsApply = true; | 214 this._needsApply = true; |
212 return; | 215 return; |
213 } | 216 } |
214 | 217 |
215 if (!ElemHide.isDirty || !Prefs.enabled) | 218 let enabled = Prefs.enabled && Prefs.element_hiding_enabled; |
| 219 |
| 220 if (!ElemHide.isDirty || !enabled) |
216 { | 221 { |
217 // Nothing changed, looks like we merely got enabled/disabled | 222 // Nothing changed, looks like we merely got enabled/disabled |
218 if (Prefs.enabled && !ElemHide.applied) | 223 if (enabled && !ElemHide.applied) |
219 { | 224 { |
220 try | 225 try |
221 { | 226 { |
222 Utils.styleService.loadAndRegisterSheet(styleURL, Ci.nsIStyleSheetServ
ice.USER_SHEET); | 227 Utils.styleService.loadAndRegisterSheet(styleURL, Ci.nsIStyleSheetServ
ice.USER_SHEET); |
223 ElemHide.applied = true; | 228 ElemHide.applied = true; |
224 } | 229 } |
225 catch (e) | 230 catch (e) |
226 { | 231 { |
227 Cu.reportError(e); | 232 Cu.reportError(e); |
228 } | 233 } |
229 } | 234 } |
230 else if (!Prefs.enabled && ElemHide.applied) | 235 else if (!enabled && ElemHide.applied) |
231 { | 236 { |
232 ElemHide.unapply(); | 237 ElemHide.unapply(); |
233 } | 238 } |
234 | 239 |
235 return; | 240 return; |
236 } | 241 } |
237 | 242 |
238 IO.writeToFile(styleURL.file, this._generateCSSContent(), function(e) | 243 IO.writeToFile(styleURL.file, this._generateCSSContent(), function(e) |
239 { | 244 { |
240 this._applying = false; | 245 this._applying = false; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 let filter = filterByKey[key]; | 389 let filter = filterByKey[key]; |
385 if (specificOnly && (!filter.domains || filter.domains[""])) | 390 if (specificOnly && (!filter.domains || filter.domains[""])) |
386 continue; | 391 continue; |
387 | 392 |
388 if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain)) | 393 if (filter.isActiveOnDomain(domain) && !this.getException(filter, domain)) |
389 result.push(filter.selector); | 394 result.push(filter.selector); |
390 } | 395 } |
391 return result; | 396 return result; |
392 } | 397 } |
393 }; | 398 }; |
OLD | NEW |