| Left: | ||
| Right: |
| 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 16 matching lines...) Expand all Loading... | |
| 201 addSelectors(selectors, filters) | 206 addSelectors(selectors, filters) |
| 202 { | 207 { |
| 203 let pairs = selectors.map((sel, i) => [sel, filters && filters[i]]); | 208 let pairs = selectors.map((sel, i) => [sel, filters && filters[i]]); |
| 204 | 209 |
| 205 if (document.readyState != "loading") | 210 if (document.readyState != "loading") |
| 206 this.checkNodes([document], pairs); | 211 this.checkNodes([document], pairs); |
| 207 | 212 |
| 208 this.selectors.push(...pairs); | 213 this.selectors.push(...pairs); |
| 209 }, | 214 }, |
| 210 | 215 |
| 216 reportFilters(selectors, filters) | |
| 217 { | |
| 218 let matchedSelectors = []; | |
| 219 for (let filter of filters) | |
| 220 matchedSelectors.push(filter.replace(/^.*?##/, "")); | |
|
Sebastian Noack
2017/04/07 13:14:47
This is essentially dead code.
Now after rebasing
hub
2017/04/07 15:50:01
ah ok. done now.
| |
| 221 | |
| 222 ext.backgroundPage.sendMessage({ | |
| 223 type: "devtools.traceElemHide", | |
| 224 selectors, filters | |
| 225 }); | |
| 226 }, | |
| 227 | |
| 211 checkNodes(nodes, pairs) | 228 checkNodes(nodes, pairs) |
| 212 { | 229 { |
| 213 let selectors = []; | 230 let selectors = []; |
| 214 let filters = []; | 231 let filters = []; |
| 215 | 232 |
| 216 for (let [selector, filter] of pairs) | 233 for (let [selector, filter] of pairs) |
| 217 { | 234 { |
| 218 nodes: for (let node of nodes) | 235 nodes: for (let node of nodes) |
| 219 { | 236 { |
| 220 for (let element of node.querySelectorAll(selector)) | 237 for (let element of node.querySelectorAll(selector)) |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 234 else | 251 else |
| 235 selectors.push(selector); | 252 selectors.push(selector); |
| 236 | 253 |
| 237 break nodes; | 254 break nodes; |
| 238 } | 255 } |
| 239 } | 256 } |
| 240 } | 257 } |
| 241 } | 258 } |
| 242 | 259 |
| 243 if (selectors.length > 0 || filters.length > 0) | 260 if (selectors.length > 0 || filters.length > 0) |
| 244 { | 261 this.reportFilters(selectors, filters); |
| 245 ext.backgroundPage.sendMessage({ | |
| 246 type: "devtools.traceElemHide", | |
| 247 selectors, filters | |
| 248 }); | |
| 249 } | |
| 250 }, | 262 }, |
| 251 | 263 |
| 252 onTimeout() | 264 onTimeout() |
| 253 { | 265 { |
| 254 this.checkNodes(this.changedNodes, this.selectors); | 266 this.checkNodes(this.changedNodes, this.selectors); |
| 255 this.changedNodes = []; | 267 this.changedNodes = []; |
| 256 this.timeout = null; | 268 this.timeout = null; |
| 257 }, | 269 }, |
| 258 | 270 |
| 259 observe(mutations) | 271 observe(mutations) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 | 441 |
| 430 this.elemHideEmulation = new ElemHideEmulation( | 442 this.elemHideEmulation = new ElemHideEmulation( |
| 431 window, | 443 window, |
| 432 callback => | 444 callback => |
| 433 { | 445 { |
| 434 ext.backgroundPage.sendMessage({ | 446 ext.backgroundPage.sendMessage({ |
| 435 type: "filters.get", | 447 type: "filters.get", |
| 436 what: "elemhideemulation" | 448 what: "elemhideemulation" |
| 437 }, callback); | 449 }, callback); |
| 438 }, | 450 }, |
| 439 this.addSelectors.bind(this) | 451 this.addSelectors.bind(this), |
| 452 this.hideElements.bind(this) | |
| 440 ); | 453 ); |
| 441 } | 454 } |
| 442 ElemHide.prototype = { | 455 ElemHide.prototype = { |
| 443 selectorGroupSize: 200, | 456 selectorGroupSize: 200, |
| 444 | 457 |
| 445 createShadowTree() | 458 createShadowTree() |
| 446 { | 459 { |
| 447 // Use Shadow DOM if available as to not mess with with web pages that | 460 // 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 | 461 // 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 | 462 // 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 | 553 i, i + this.selectorGroupSize |
| 541 ).join(", "); | 554 ).join(", "); |
| 542 this.style.sheet.insertRule(selector + "{display: none !important;}", | 555 this.style.sheet.insertRule(selector + "{display: none !important;}", |
| 543 this.style.sheet.cssRules.length); | 556 this.style.sheet.cssRules.length); |
| 544 } | 557 } |
| 545 | 558 |
| 546 if (this.tracer) | 559 if (this.tracer) |
| 547 this.tracer.addSelectors(selectors, filters); | 560 this.tracer.addSelectors(selectors, filters); |
| 548 }, | 561 }, |
| 549 | 562 |
| 563 hideElements(elements, filters) | |
| 564 { | |
| 565 for (let element of elements) | |
| 566 hideElement(element); | |
| 567 | |
| 568 if (this.tracer) | |
| 569 { | |
| 570 let selectors = []; | |
| 571 for (let filter of filters) | |
| 572 selectors.push(filter.replace(/^.*?##/, "")); | |
| 573 this.tracer.reportFilters(selectors, filters); | |
| 574 } | |
| 575 }, | |
| 576 | |
| 550 apply() | 577 apply() |
| 551 { | 578 { |
| 552 ext.backgroundPage.sendMessage({type: "get-selectors"}, response => | 579 ext.backgroundPage.sendMessage({type: "get-selectors"}, response => |
| 553 { | 580 { |
| 554 if (this.tracer) | 581 if (this.tracer) |
| 555 this.tracer.disconnect(); | 582 this.tracer.disconnect(); |
| 556 this.tracer = null; | 583 this.tracer = null; |
| 557 | 584 |
| 558 if (this.style && this.style.parentElement) | 585 if (this.style && this.style.parentElement) |
| 559 this.style.parentElement.removeChild(this.style); | 586 this.style.parentElement.removeChild(this.style); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 581 checkCollapse(event.target); | 608 checkCollapse(event.target); |
| 582 }, true); | 609 }, true); |
| 583 | 610 |
| 584 document.addEventListener("load", event => | 611 document.addEventListener("load", event => |
| 585 { | 612 { |
| 586 let element = event.target; | 613 let element = event.target; |
| 587 if (/^i?frame$/.test(element.localName)) | 614 if (/^i?frame$/.test(element.localName)) |
| 588 checkCollapse(element); | 615 checkCollapse(element); |
| 589 }, true); | 616 }, true); |
| 590 } | 617 } |
| OLD | NEW |