| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 var SELECTOR_GROUP_SIZE = 20; | 18 var SELECTOR_GROUP_SIZE = 20; |
| 19 | 19 |
| 20 // use Shadow DOM if available to don't mess with web pages that |
| 21 // rely on the order of their own <style> tags. However |
| 22 // the <shadow> element is broken in some Chrome 32 builds (#309) |
| 23 // |
| 24 // also we must not create the shadow root in the response callback passed |
| 25 // to sendMessage(), otherwise Chrome breaks some websites (#450) |
| 26 var shadow = null; |
| 27 if ("webkitCreateShadowRoot" in document.documentElement && !/\bChrome\/32\b/.te
st(navigator.userAgent)) |
| 28 { |
| 29 shadow = document.documentElement.webkitCreateShadowRoot(); |
| 30 shadow.appendChild(document.createElement("shadow")); |
| 31 } |
| 32 |
| 20 // Sets the currently used CSS rules for elemhide filters | 33 // Sets the currently used CSS rules for elemhide filters |
| 21 function setElemhideCSSRules(selectors) | 34 function setElemhideCSSRules(selectors) |
| 22 { | 35 { |
| 23 if (selectors.length == 0) | 36 if (selectors.length == 0) |
| 24 return; | 37 return; |
| 25 | 38 |
| 26 var style = document.createElement("style"); | 39 var style = document.createElement("style"); |
| 27 style.setAttribute("type", "text/css"); | 40 style.setAttribute("type", "text/css"); |
| 28 | 41 |
| 29 // Use Shadow DOM if available to don't mess with web pages that | 42 if (shadow) |
| 30 // rely on the order of their own <style> tags. However | |
| 31 // the <shadow> element is broken in some Chrome 32 builts (#309) | |
| 32 if ("webkitCreateShadowRoot" in document.documentElement && !/\bChrome\/32\b/.
test(navigator.userAgent)) | |
| 33 { | 43 { |
| 34 var shadow = document.documentElement.webkitCreateShadowRoot(); | |
| 35 shadow.appendChild(document.createElement("shadow")); | |
| 36 shadow.appendChild(style); | 44 shadow.appendChild(style); |
| 37 | 45 |
| 38 try | 46 try |
| 39 { | 47 { |
| 40 document.querySelector("::content"); | 48 document.querySelector("::content"); |
| 41 | 49 |
| 42 for (var i = 0; i < selectors.length; i++) | 50 for (var i = 0; i < selectors.length; i++) |
| 43 selectors[i] = "::content " + selectors[i]; | 51 selectors[i] = "::content " + selectors[i]; |
| 44 } | 52 } |
| 45 catch (e) | 53 catch (e) |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr}); | 130 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr}); |
| 123 | 131 |
| 124 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); | 132 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); |
| 125 } | 133 } |
| 126 | 134 |
| 127 // In Chrome 18 the document might not be initialized yet | 135 // In Chrome 18 the document might not be initialized yet |
| 128 if (document.documentElement) | 136 if (document.documentElement) |
| 129 init(); | 137 init(); |
| 130 else | 138 else |
| 131 window.setTimeout(init, 0); | 139 window.setTimeout(init, 0); |
| OLD | NEW |