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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 for (let i = 0; i < urls.length; i++) | 121 for (let i = 0; i < urls.length; i++) |
122 { | 122 { |
123 if (/^(?!https?:)[\w-]+:/i.test(urls[i])) | 123 if (/^(?!https?:)[\w-]+:/i.test(urls[i])) |
124 urls.splice(i--, 1); | 124 urls.splice(i--, 1); |
125 } | 125 } |
126 | 126 |
127 return urls; | 127 return urls; |
128 } | 128 } |
129 | 129 |
| 130 function hideElement(element) |
| 131 { |
| 132 function doHide(element) |
| 133 { |
| 134 let propertyName = "display"; |
| 135 let propertyValue = "none"; |
| 136 if (element.localName == "frame") |
| 137 { |
| 138 propertyName = "visibility"; |
| 139 propertyValue = "hidden"; |
| 140 } |
| 141 |
| 142 if (element.style.getPropertyValue(propertyName) != propertyValue || |
| 143 element.style.getPropertyPriority(propertyName) != "important") |
| 144 element.style.setProperty(propertyName, propertyValue, "important"); |
| 145 } |
| 146 |
| 147 doHide(element); |
| 148 |
| 149 new MutationObserver(doHide).observe( |
| 150 element, { |
| 151 attributes: true, |
| 152 attributeFilter: ["style"] |
| 153 } |
| 154 ); |
| 155 } |
| 156 |
130 function checkCollapse(element) | 157 function checkCollapse(element) |
131 { | 158 { |
132 let mediatype = typeMap.get(element.localName); | 159 let mediatype = typeMap.get(element.localName); |
133 if (!mediatype) | 160 if (!mediatype) |
134 return; | 161 return; |
135 | 162 |
136 let urls = getURLsFromElement(element); | 163 let urls = getURLsFromElement(element); |
137 if (urls.length == 0) | 164 if (urls.length == 0) |
138 return; | 165 return; |
139 | 166 |
140 ext.backgroundPage.sendMessage( | 167 ext.backgroundPage.sendMessage( |
141 { | 168 { |
142 type: "filters.collapse", | 169 type: "filters.collapse", |
143 urls, | 170 urls, |
144 mediatype, | 171 mediatype, |
145 baseURL: document.location.href | 172 baseURL: document.location.href |
146 }, | 173 }, |
147 | 174 |
148 collapse => | 175 collapse => |
149 { | 176 { |
150 function collapseElement() | |
151 { | |
152 let propertyName = "display"; | |
153 let propertyValue = "none"; | |
154 if (element.localName == "frame") | |
155 { | |
156 propertyName = "visibility"; | |
157 propertyValue = "hidden"; | |
158 } | |
159 | |
160 if (element.style.getPropertyValue(propertyName) != propertyValue || | |
161 element.style.getPropertyPriority(propertyName) != "important") | |
162 element.style.setProperty(propertyName, propertyValue, "important"); | |
163 } | |
164 | |
165 if (collapse) | 177 if (collapse) |
166 { | 178 { |
167 collapseElement(); | 179 hideElement(element); |
168 | |
169 new MutationObserver(collapseElement).observe( | |
170 element, { | |
171 attributes: true, | |
172 attributeFilter: ["style"] | |
173 } | |
174 ); | |
175 } | 180 } |
176 } | 181 } |
177 ); | 182 ); |
178 } | 183 } |
179 | 184 |
180 function checkSitekey() | 185 function checkSitekey() |
181 { | 186 { |
182 let attr = document.documentElement.getAttribute("data-adblockkey"); | 187 let attr = document.documentElement.getAttribute("data-adblockkey"); |
183 if (attr) | 188 if (attr) |
184 ext.backgroundPage.sendMessage({type: "filters.addKey", token: attr}); | 189 ext.backgroundPage.sendMessage({type: "filters.addKey", token: attr}); |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 | 434 |
430 this.elemHideEmulation = new ElemHideEmulation( | 435 this.elemHideEmulation = new ElemHideEmulation( |
431 window, | 436 window, |
432 callback => | 437 callback => |
433 { | 438 { |
434 ext.backgroundPage.sendMessage({ | 439 ext.backgroundPage.sendMessage({ |
435 type: "filters.get", | 440 type: "filters.get", |
436 what: "elemhideemulation" | 441 what: "elemhideemulation" |
437 }, callback); | 442 }, callback); |
438 }, | 443 }, |
439 this.addSelectors.bind(this) | 444 this.addSelectors.bind(this), |
| 445 this.hideElements.bind(this) |
440 ); | 446 ); |
441 } | 447 } |
442 ElemHide.prototype = { | 448 ElemHide.prototype = { |
443 selectorGroupSize: 200, | 449 selectorGroupSize: 200, |
444 | 450 |
445 createShadowTree() | 451 createShadowTree() |
446 { | 452 { |
447 // Use Shadow DOM if available as to not mess with with web pages that | 453 // Use Shadow DOM if available as to not mess with with web pages that |
448 // rely on the order of their own <style> tags (#309). However, creating | 454 // rely on the order of their own <style> tags (#309). However, creating |
449 // a shadow root breaks running CSS transitions. So we have to create | 455 // a shadow root breaks running CSS transitions. So we have to create |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 i, i + this.selectorGroupSize | 546 i, i + this.selectorGroupSize |
541 ).join(", "); | 547 ).join(", "); |
542 this.style.sheet.insertRule(selector + "{display: none !important;}", | 548 this.style.sheet.insertRule(selector + "{display: none !important;}", |
543 this.style.sheet.cssRules.length); | 549 this.style.sheet.cssRules.length); |
544 } | 550 } |
545 | 551 |
546 if (this.tracer) | 552 if (this.tracer) |
547 this.tracer.addSelectors(selectors, filters); | 553 this.tracer.addSelectors(selectors, filters); |
548 }, | 554 }, |
549 | 555 |
| 556 hideElements(elements, filters) |
| 557 { |
| 558 for (let element of elements) |
| 559 hideElement(element); |
| 560 |
| 561 if (this.tracer) |
| 562 ext.backgroundPage.sendMessage({ |
| 563 type: "devtools.traceElemHide", |
| 564 selectors: [], |
| 565 filters |
| 566 }); |
| 567 }, |
| 568 |
550 apply() | 569 apply() |
551 { | 570 { |
552 ext.backgroundPage.sendMessage({type: "get-selectors"}, response => | 571 ext.backgroundPage.sendMessage({type: "get-selectors"}, response => |
553 { | 572 { |
554 if (this.tracer) | 573 if (this.tracer) |
555 this.tracer.disconnect(); | 574 this.tracer.disconnect(); |
556 this.tracer = null; | 575 this.tracer = null; |
557 | 576 |
558 if (this.style && this.style.parentElement) | 577 if (this.style && this.style.parentElement) |
559 this.style.parentElement.removeChild(this.style); | 578 this.style.parentElement.removeChild(this.style); |
(...skipping 21 matching lines...) Expand all Loading... |
581 checkCollapse(event.target); | 600 checkCollapse(event.target); |
582 }, true); | 601 }, true); |
583 | 602 |
584 document.addEventListener("load", event => | 603 document.addEventListener("load", event => |
585 { | 604 { |
586 let element = event.target; | 605 let element = event.target; |
587 if (/^i?frame$/.test(element.localName)) | 606 if (/^i?frame$/.test(element.localName)) |
588 checkCollapse(element); | 607 checkCollapse(element); |
589 }, true); | 608 }, true); |
590 } | 609 } |
OLD | NEW |