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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 { | 126 { |
127 if (/^(?!https?:)[\w-]+:/i.test(urls[i])) | 127 if (/^(?!https?:)[\w-]+:/i.test(urls[i])) |
128 urls.splice(i--, 1); | 128 urls.splice(i--, 1); |
129 } | 129 } |
130 | 130 |
131 return urls; | 131 return urls; |
132 } | 132 } |
133 | 133 |
134 function getSelectorForBlockedElement(element) | 134 function getSelectorForBlockedElement(element) |
135 { | 135 { |
136 // Microsoft Edge does not support CSS.escape(). However, it doesn't | |
137 // support user style sheets either. So the selector would be added | |
138 // with an author style sheet anyway, which doesn't provide any benefits. | |
139 if (!("escape" in CSS)) | |
140 return null; | |
141 | |
136 // Setting the "display" CSS property to "none" doesn't have any effect on | 142 // Setting the "display" CSS property to "none" doesn't have any effect on |
137 // <frame> elements (in framesets). So we have to hide it inline through | 143 // <frame> elements (in framesets). So we have to hide it inline through |
138 // the "visisiblity" CSS property. | 144 // the "visibility" CSS property. |
Manish Jethani
2018/05/07 17:42:02
Typo: visibility
Sebastian Noack
2018/05/09 16:30:46
Done.
| |
139 if (element.localName == "frame") | 145 if (element.localName == "frame") |
140 return null; | 146 return null; |
141 | 147 |
142 // If the <video> or <audio> element contains any <source> or <track> | 148 // If the <video> or <audio> element contains any <source> or <track> |
143 // children, we cannot address it in CSS by the source URL; in that case we | 149 // children, we cannot address it in CSS by the source URL; in that case we |
144 // don't "collapse" it using a CSS selector but rather hide it directly by | 150 // don't "collapse" it using a CSS selector but rather hide it directly by |
145 // setting the style="..." attribute. | 151 // setting the style="..." attribute. |
146 if (element.localName == "video" || element.localName == "audio") | 152 if (element.localName == "video" || element.localName == "audio") |
147 { | 153 { |
148 for (let child of element.children) | 154 for (let child of element.children) |
149 { | 155 { |
150 if (child.localName == "source" || child.localName == "track") | 156 if (child.localName == "source" || child.localName == "track") |
151 return null; | 157 return null; |
152 } | 158 } |
153 } | 159 } |
154 | 160 |
155 // Microsoft Edge does not support CSS.escape(). However, it doesn't | 161 let selector = ""; |
Manish Jethani
2018/05/07 17:42:02
Shouldn't this go before the above if block?
Sebastian Noack
2018/05/09 16:30:46
Done.
| |
156 // support user style sheets either. So the selector would be added | |
157 // with an author style sheet anyway, which doesn't provide any benefits. | |
158 if (!("escape" in CSS)) | |
159 return null; | |
160 | |
161 let selector = element.localName; | |
162 let hasSrc = false; | |
163 for (let attr of ["src", "srcset"]) | 162 for (let attr of ["src", "srcset"]) |
164 { | 163 { |
165 let value = element.getAttribute(attr); | 164 let value = element.getAttribute(attr); |
166 if (value && attr in element) | 165 if (value && attr in element) |
Manish Jethani
2018/05/07 17:42:02
Any reason why we're checking attr in element here
Sebastian Noack
2018/05/09 16:30:46
Yes, we only want to consider the src/srcset attri
Manish Jethani
2018/05/09 23:11:09
Acknowledged.
| |
167 { | |
168 selector += "[" + attr + "=" + CSS.escape(value) + "]"; | 166 selector += "[" + attr + "=" + CSS.escape(value) + "]"; |
169 hasSrc = true; | 167 } |
170 } | 168 |
171 } | 169 return selector ? element.localName + selector : null; |
172 | |
173 return hasSrc ? selector : null; | |
174 } | 170 } |
175 | 171 |
176 function hideElement(element) | 172 function hideElement(element) |
177 { | 173 { |
178 function doHide() | 174 function doHide() |
179 { | 175 { |
180 let propertyName = "display"; | 176 let propertyName = "display"; |
181 let propertyValue = "none"; | 177 let propertyValue = "none"; |
182 if (element.localName == "frame") | 178 if (element.localName == "frame") |
183 { | 179 { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 | 297 |
302 break nodes; | 298 break nodes; |
303 } | 299 } |
304 } | 300 } |
305 } | 301 } |
306 } | 302 } |
307 | 303 |
308 if (selectors.length > 0 || filters.length > 0) | 304 if (selectors.length > 0 || filters.length > 0) |
309 { | 305 { |
310 browser.runtime.sendMessage({ | 306 browser.runtime.sendMessage({ |
311 type: "devtools.traceElemHide", | 307 type: "hitLogger.traceElemHide", |
312 selectors, filters | 308 selectors, filters |
313 }); | 309 }); |
314 } | 310 } |
315 }, | 311 }, |
316 | 312 |
317 onTimeout() | 313 onTimeout() |
318 { | 314 { |
319 this.checkNodes(this.changedNodes, this.selectors); | 315 this.checkNodes(this.changedNodes, this.selectors); |
320 this.changedNodes = []; | 316 this.changedNodes = []; |
321 this.timeout = null; | 317 this.timeout = null; |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
548 }, | 544 }, |
549 | 545 |
550 hideElements(elements, filters) | 546 hideElements(elements, filters) |
551 { | 547 { |
552 for (let element of elements) | 548 for (let element of elements) |
553 hideElement(element); | 549 hideElement(element); |
554 | 550 |
555 if (this.tracer) | 551 if (this.tracer) |
556 { | 552 { |
557 browser.runtime.sendMessage({ | 553 browser.runtime.sendMessage({ |
558 type: "devtools.traceElemHide", | 554 type: "hitLogger.traceElemHide", |
559 selectors: [], | 555 selectors: [], |
560 filters | 556 filters |
561 }); | 557 }); |
562 } | 558 } |
563 }, | 559 }, |
564 | 560 |
565 apply() | 561 apply() |
566 { | 562 { |
567 browser.runtime.sendMessage({type: "elemhide.getSelectors"}, response => | 563 browser.runtime.sendMessage({type: "elemhide.getSelectors"}, response => |
568 { | 564 { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 let element = event.target; | 605 let element = event.target; |
610 if (/^i?frame$/.test(element.localName)) | 606 if (/^i?frame$/.test(element.localName)) |
611 checkCollapse(element); | 607 checkCollapse(element); |
612 }, true); | 608 }, true); |
613 } | 609 } |
614 | 610 |
615 window.checkCollapse = checkCollapse; | 611 window.checkCollapse = checkCollapse; |
616 window.elemhide = elemhide; | 612 window.elemhide = elemhide; |
617 window.typeMap = typeMap; | 613 window.typeMap = typeMap; |
618 window.getURLsFromElement = getURLsFromElement; | 614 window.getURLsFromElement = getURLsFromElement; |
LEFT | RIGHT |