 Issue 29370970:
  [adblockpluschrome] Issue 3596 - Added support for CSS property filters to devtools panel  (Closed)
    
  
    Issue 29370970:
  [adblockpluschrome] Issue 3596 - Added support for CSS property filters to devtools panel  (Closed) 
  | 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 { | 227 { | 
| 228 let elements = node.querySelectorAll(selectors[i]); | 228 let elements = node.querySelectorAll(selectors[i]); | 
| 229 | 229 | 
| 230 for (let element of elements) | 230 for (let element of elements) | 
| 231 { | 231 { | 
| 232 // Only consider selectors that actually have an effect on the | 232 // Only consider selectors that actually have an effect on the | 
| 233 // computed styles, and aren't overridden by rules with higher | 233 // computed styles, and aren't overridden by rules with higher | 
| 234 // priority, or haven't been circumvented in a different way. | 234 // priority, or haven't been circumvented in a different way. | 
| 235 if (getComputedStyle(element).display == "none") | 235 if (getComputedStyle(element).display == "none") | 
| 236 { | 236 { | 
| 237 let filter = filters[i] || selectors[i]; | 237 matchedSelectors.push(filters[i].replace(/^.*?##/, "")); | 
| 
Sebastian Noack
2017/02/23 11:08:23
This is no longer necessary. You don't have to con
 
wspee
2017/02/23 11:20:21
Done.
 | |
| 238 matchedSelectors.push(filter.replace(/^.*?##/, "")); | |
| 239 break nodes; | 238 break nodes; | 
| 240 } | 239 } | 
| 241 } | 240 } | 
| 242 } | 241 } | 
| 243 } | 242 } | 
| 244 | 243 | 
| 245 if (matchedSelectors.length > 0) | 244 if (matchedSelectors.length > 0) | 
| 246 ext.backgroundPage.sendMessage({ | 245 ext.backgroundPage.sendMessage({ | 
| 247 type: "devtools.traceElemHide", | 246 type: "devtools.traceElemHide", | 
| 248 selectors: matchedSelectors | 247 selectors: matchedSelectors | 
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 538 // is! Edge apparently has no such limit.) | 537 // is! Edge apparently has no such limit.) | 
| 539 // [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69 debb75fc1de/Source/WebCore/css/RuleSet.h#L68 | 538 // [1] - https://github.com/WebKit/webkit/blob/1cb2227f6b2a1035f7bdc46e5ab69 debb75fc1de/Source/WebCore/css/RuleSet.h#L68 | 
| 540 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize) | 539 for (let i = 0; i < preparedSelectors.length; i += this.selectorGroupSize) | 
| 541 { | 540 { | 
| 542 let selector = preparedSelectors.slice(i, i + this.selectorGroupSize).join (", "); | 541 let selector = preparedSelectors.slice(i, i + this.selectorGroupSize).join (", "); | 
| 543 this.style.sheet.insertRule(selector + "{display: none !important;}", | 542 this.style.sheet.insertRule(selector + "{display: none !important;}", | 
| 544 this.style.sheet.cssRules.length); | 543 this.style.sheet.cssRules.length); | 
| 545 } | 544 } | 
| 546 | 545 | 
| 547 if (this.tracer) | 546 if (this.tracer) | 
| 548 this.tracer.addSelectors(selectors, filters); | 547 this.tracer.addSelectors(selectors, filters || selectors); | 
| 549 }, | 548 }, | 
| 550 | 549 | 
| 551 apply() | 550 apply() | 
| 552 { | 551 { | 
| 553 ext.backgroundPage.sendMessage({type: "get-selectors"}, response => | 552 ext.backgroundPage.sendMessage({type: "get-selectors"}, response => | 
| 554 { | 553 { | 
| 555 if (this.tracer) | 554 if (this.tracer) | 
| 556 this.tracer.disconnect(); | 555 this.tracer.disconnect(); | 
| 557 this.tracer = null; | 556 this.tracer = null; | 
| 558 | 557 | 
| 559 if (this.style && this.style.parentElement) | 558 if (this.style && this.style.parentElement) | 
| 560 this.style.parentElement.removeChild(this.style); | 559 this.style.parentElement.removeChild(this.style); | 
| 561 this.style = null; | 560 this.style = null; | 
| 562 | 561 | 
| 563 if (response.trace) | 562 if (response.trace) | 
| 564 this.tracer = new ElementHidingTracer(); | 563 this.tracer = new ElementHidingTracer(); | 
| 565 | 564 | 
| 566 this.addSelectors(response.selectors, response.selectors); | 565 this.addSelectors(response.selectors); | 
| 
Sebastian Noack
2017/02/23 11:24:03
I wonder whether it would be nicer to handle this
 
wspee
2017/02/23 14:24:48
Done.
 | |
| 567 | |
| 568 this.elemHideEmulation.apply(); | 566 this.elemHideEmulation.apply(); | 
| 569 }); | 567 }); | 
| 570 } | 568 } | 
| 571 }; | 569 }; | 
| 572 | 570 | 
| 573 if (document instanceof HTMLDocument) | 571 if (document instanceof HTMLDocument) | 
| 574 { | 572 { | 
| 575 checkSitekey(); | 573 checkSitekey(); | 
| 576 wrapWebSocket(); | 574 wrapWebSocket(); | 
| 577 | 575 | 
| 578 // This variable is also used by our other content scripts, outside of the | 576 // This variable is also used by our other content scripts, outside of the | 
| 579 // current scope. | 577 // current scope. | 
| 580 var elemhide = new ElemHide(); | 578 var elemhide = new ElemHide(); | 
| 581 elemhide.apply(); | 579 elemhide.apply(); | 
| 582 | 580 | 
| 583 document.addEventListener("error", event => | 581 document.addEventListener("error", event => | 
| 584 { | 582 { | 
| 585 checkCollapse(event.target); | 583 checkCollapse(event.target); | 
| 586 }, true); | 584 }, true); | 
| 587 | 585 | 
| 588 document.addEventListener("load", event => | 586 document.addEventListener("load", event => | 
| 589 { | 587 { | 
| 590 let element = event.target; | 588 let element = event.target; | 
| 591 if (/^i?frame$/.test(element.localName)) | 589 if (/^i?frame$/.test(element.localName)) | 
| 592 checkCollapse(element); | 590 checkCollapse(element); | 
| 593 }, true); | 591 }, true); | 
| 594 } | 592 } | 
| LEFT | RIGHT |