| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 else | 173 else |
| 174 { | 174 { |
| 175 // The new filter's selector only applies to some domains | 175 // The new filter's selector only applies to some domains |
| 176 this._addToFiltersByDomain(key, filter); | 176 this._addToFiltersByDomain(key, filter); |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 FilterNotifier.emit("elemhideupdate"); | 180 FilterNotifier.emit("elemhideupdate"); |
| 181 }, | 181 }, |
| 182 | 182 |
| 183 /** | 183 _removeFilterKey: function(key, filter) |
| 184 * Removes an element hiding filter | 184 { |
| 185 * @param {ElemHideFilter} filter | 185 let filterKeys = filterKeysBySelector[filter.selector]; |
| 186 */ | 186 if (filterKeys) |
| 187 remove: function(filter) | 187 { |
| 188 { | 188 let index = filterKeys.indexOf(key); |
| 189 if (filter instanceof ElemHideException) | |
| 190 { | |
| 191 if (!(filter.text in knownExceptions)) | |
| 192 return; | |
| 193 | |
| 194 let list = exceptions[filter.selector]; | |
| 195 let index = list.indexOf(filter); | |
| 196 if (index >= 0) | 189 if (index >= 0) |
| 197 list.splice(index, 1); | |
| 198 delete knownExceptions[filter.text]; | |
| 199 } | |
| 200 else | |
| 201 { | |
| 202 if (!(filter.text in keyByFilter)) | |
| 203 return; | |
| 204 | |
| 205 let key = keyByFilter[filter.text]; | |
| 206 delete filterByKey[key]; | |
| 207 delete keyByFilter[filter.text]; | |
| 208 | |
| 209 let filterKeys = filterKeysBySelector[filter.selector]; | |
| 210 if (filterKeys) | |
| 211 { | 190 { |
| 212 if (filterKeys.length > 1) | 191 if (filterKeys.length > 1) |
| 213 { | 192 { |
| 214 let index = filterKeys.indexOf(key); | |
| 215 filterKeys.splice(index, 1); | 193 filterKeys.splice(index, 1); |
|
Wladimir Palant
2016/09/20 10:36:07
We need to null out unconditionalFilterKeys here i
kzar
2016/09/20 14:23:48
Good point, Done.
| |
| 194 if (index == 0) | |
| 195 unconditionalFilterKeys = null; | |
| 216 } | 196 } |
| 217 else | 197 else |
| 218 { | 198 { |
| 219 delete filterKeysBySelector[filter.selector]; | 199 delete filterKeysBySelector[filter.selector]; |
| 220 unconditionalSelectors = unconditionalFilterKeys = null; | 200 unconditionalSelectors = unconditionalFilterKeys = null; |
| 221 } | 201 } |
| 202 return; | |
| 222 } | 203 } |
| 223 else | 204 } |
| 224 { | 205 |
| 225 let domains = filter.domains || defaultDomains; | 206 // We haven't found this filter in unconditional filters, look in |
| 226 for (let domain in domains) | 207 // filtersByDomain. |
| 227 { | 208 let domains = filter.domains || defaultDomains; |
| 228 let filters = filtersByDomain[domain]; | 209 for (let domain in domains) |
| 229 if (filters) | 210 { |
| 230 delete filters[key]; | 211 let filters = filtersByDomain[domain]; |
| 231 } | 212 if (filters) |
| 232 } | 213 delete filters[key]; |
| 214 } | |
| 215 }, | |
| 216 | |
| 217 /** | |
| 218 * Removes an element hiding filter | |
| 219 * @param {ElemHideFilter} filter | |
| 220 */ | |
| 221 remove: function(filter) | |
| 222 { | |
| 223 if (filter instanceof ElemHideException) | |
| 224 { | |
| 225 if (!(filter.text in knownExceptions)) | |
| 226 return; | |
| 227 | |
| 228 let list = exceptions[filter.selector]; | |
| 229 let index = list.indexOf(filter); | |
| 230 if (index >= 0) | |
| 231 list.splice(index, 1); | |
| 232 delete knownExceptions[filter.text]; | |
| 233 } | |
| 234 else | |
| 235 { | |
| 236 if (!(filter.text in keyByFilter)) | |
| 237 return; | |
| 238 | |
| 239 let key = keyByFilter[filter.text]; | |
| 240 delete filterByKey[key]; | |
| 241 delete keyByFilter[filter.text]; | |
| 242 this._removeFilterKey(key, filter); | |
| 233 } | 243 } |
| 234 | 244 |
| 235 FilterNotifier.emit("elemhideupdate"); | 245 FilterNotifier.emit("elemhideupdate"); |
| 236 }, | 246 }, |
| 237 | 247 |
| 238 /** | 248 /** |
| 239 * Checks whether an exception rule is registered for a filter on a particular | 249 * Checks whether an exception rule is registered for a filter on a particular |
| 240 * domain. | 250 * domain. |
| 241 */ | 251 */ |
| 242 getException: function(/**Filter*/ filter, /**String*/ docDomain) /**ElemHideE xception*/ | 252 getException: function(/**Filter*/ filter, /**String*/ docDomain) /**ElemHideE xception*/ |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 if (!unconditionalFilterKeys) | 319 if (!unconditionalFilterKeys) |
| 310 { | 320 { |
| 311 let selectors = this.getUnconditionalSelectors(); | 321 let selectors = this.getUnconditionalSelectors(); |
| 312 unconditionalFilterKeys = []; | 322 unconditionalFilterKeys = []; |
| 313 for (let selector of selectors) | 323 for (let selector of selectors) |
| 314 unconditionalFilterKeys.push(filterKeysBySelector[selector][0]); | 324 unconditionalFilterKeys.push(filterKeysBySelector[selector][0]); |
| 315 } | 325 } |
| 316 return unconditionalFilterKeys.slice(); | 326 return unconditionalFilterKeys.slice(); |
| 317 }, | 327 }, |
| 318 | 328 |
| 319 /** | 329 |
| 320 * Returns a list of all selectors active on a particular domain. Optionally | 330 /** |
| 321 * a list of corresponding filter keys for the selectors can be returned too. | 331 * Constant used by getSelectorsForDomain to return all selectors applying to |
| 322 */ | 332 * a particular hostname. |
| 323 getSelectorsForDomain: function(/**String*/ domain, /**Boolean*/ specificOnly, | 333 */ |
| 324 /**Boolean*/ noUnconditional, | 334 ALL_MATCHING: 0, |
| 325 /**Boolean*/ provideFilterKeys) | 335 |
| 336 /** | |
| 337 * Constant used by getSelectorsForDomain to exclude selectors which apply to | |
| 338 * all websites without exception. | |
| 339 */ | |
| 340 NO_UNCONDITIONAL: 1, | |
| 341 | |
| 342 /** | |
| 343 * Constant used by getSelectorsForDomain to return only selectors for filters | |
| 344 * which specifically match the given host name. | |
| 345 */ | |
| 346 SPECIFIC_ONLY: 2, | |
| 347 | |
| 348 /** | |
| 349 * Determines from the current filter list which selectors should be applied | |
| 350 * on a particular host name. Optionally returns the corresponding filter | |
| 351 * keys. | |
| 352 * @param {String} domain | |
| 353 * @param {Number} [criteria] | |
| 354 * One of the following: ElemHide.ALL_MATCHING, ElemHide.NO_UNCONDITIONAL or | |
| 355 * ElemHide.SPECIFIC_ONLY. | |
| 356 * @param {Boolean} [provideFilterKeys] | |
| 357 * If true, the function will return a list of corresponding filter keys in | |
| 358 * addition to selectors. | |
| 359 * @returns {string[]|Array.<string[]>} | |
| 360 * List of selectors or an array with two elements (list of selectors and | |
| 361 * list of corresponding keys) if provideFilterKeys is true. | |
| 362 */ | |
| 363 getSelectorsForDomain: function(domain, criteria, provideFilterKeys) | |
| 326 { | 364 { |
| 327 let filterKeys = []; | 365 let filterKeys = []; |
| 328 let selectors = []; | 366 let selectors = []; |
| 329 if (!specificOnly && !noUnconditional) | 367 |
| 368 if (typeof criteria == "undefined") | |
| 369 criteria = ElemHide.ALL_MATCHING; | |
| 370 if (criteria < ElemHide.NO_UNCONDITIONAL) | |
| 330 { | 371 { |
| 331 selectors = this.getUnconditionalSelectors(); | 372 selectors = this.getUnconditionalSelectors(); |
| 332 if (provideFilterKeys) | 373 if (provideFilterKeys) |
| 333 filterKeys = this.getUnconditionalFilterKeys(); | 374 filterKeys = this.getUnconditionalFilterKeys(); |
| 334 } | 375 } |
| 335 | 376 |
| 377 let specificOnly = (criteria >= ElemHide.SPECIFIC_ONLY); | |
| 336 let seenFilters = Object.create(null); | 378 let seenFilters = Object.create(null); |
| 337 let currentDomain = domain ? domain.toUpperCase() : ""; | 379 let currentDomain = domain ? domain.toUpperCase() : ""; |
| 338 while (true) | 380 while (true) |
| 339 { | 381 { |
| 340 if (specificOnly && currentDomain == "") | 382 if (specificOnly && currentDomain == "") |
| 341 break; | 383 break; |
| 342 | 384 |
| 343 let filters = filtersByDomain[currentDomain]; | 385 let filters = filtersByDomain[currentDomain]; |
| 344 if (filters) | 386 if (filters) |
| 345 { | 387 { |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 365 let nextDot = currentDomain.indexOf("."); | 407 let nextDot = currentDomain.indexOf("."); |
| 366 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); | 408 currentDomain = nextDot == -1 ? "" : currentDomain.substr(nextDot + 1); |
| 367 } | 409 } |
| 368 | 410 |
| 369 if (provideFilterKeys) | 411 if (provideFilterKeys) |
| 370 return [selectors, filterKeys]; | 412 return [selectors, filterKeys]; |
| 371 else | 413 else |
| 372 return selectors; | 414 return selectors; |
| 373 } | 415 } |
| 374 }; | 416 }; |
| LEFT | RIGHT |