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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 var target = event.target; | 71 var target = event.target; |
72 var tag = target.localName; | 72 var tag = target.localName; |
73 var expectedEvent = (tag == "iframe" || tag == "frame" ? "load" : "error"); | 73 var expectedEvent = (tag == "iframe" || tag == "frame" ? "load" : "error"); |
74 if (tag in typeMap && event.type == expectedEvent) | 74 if (tag in typeMap && event.type == expectedEvent) |
75 { | 75 { |
76 // This element failed loading, did we block it? | 76 // This element failed loading, did we block it? |
77 var url = target.src; | 77 var url = target.src; |
78 if (!url) | 78 if (!url) |
79 return; | 79 return; |
80 | 80 |
81 var type = typeMap[tag]; | 81 ext.backgroundPage.sendMessage({ |
82 chrome.extension.sendRequest({reqtype: "should-collapse", url: url, document
Url: document.URL, type: type}, function(response) | 82 type: "should-collapse", |
83 { | 83 url: url, |
| 84 documentUrl: document.URL, |
| 85 mediatype: typeMap[tag] |
| 86 }, function(response) { |
84 if (response && target.parentNode) | 87 if (response && target.parentNode) |
85 { | 88 { |
86 // <frame> cannot be removed, doing that will mess up the frameset | 89 // <frame> cannot be removed, doing that will mess up the frameset |
87 if (tag == "frame") | 90 if (tag == "frame") |
88 target.style.setProperty("visibility", "hidden", "!important"); | 91 target.style.setProperty("visibility", "hidden", "!important"); |
89 else | 92 else |
90 target.parentNode.removeChild(target); | 93 target.parentNode.removeChild(target); |
91 } | 94 } |
92 }); | 95 }); |
93 } | 96 } |
94 } | 97 } |
95 | 98 |
96 function init() | 99 function init() |
97 { | 100 { |
98 // Make sure this is really an HTML page, as Chrome runs these scripts on just
about everything | 101 // Make sure this is really an HTML page, as Chrome runs these scripts on just
about everything |
99 if (!(document.documentElement instanceof HTMLElement)) | 102 if (!(document.documentElement instanceof HTMLElement)) |
100 return; | 103 return; |
101 | 104 |
102 document.addEventListener("error", checkCollapse, true); | 105 document.addEventListener("error", checkCollapse, true); |
103 document.addEventListener("load", checkCollapse, true); | 106 document.addEventListener("load", checkCollapse, true); |
104 | 107 |
105 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU
rl: window.location.href}, function(response) | 108 ext.backgroundPage.sendMessage({ |
106 { | 109 type: "get-settings", |
| 110 selectors: true, |
| 111 frameUrl: window.location.href |
| 112 }, function(response) { |
107 setElemhideCSSRules(response.selectors); | 113 setElemhideCSSRules(response.selectors); |
108 }); | 114 }); |
109 } | 115 } |
110 | 116 |
111 // In Chrome 18 the document might not be initialized yet | 117 // In Chrome 18 the document might not be initialized yet |
112 if (document.documentElement) | 118 if (document.documentElement) |
113 init(); | 119 init(); |
114 else | 120 else |
115 window.setTimeout(init, 0); | 121 window.setTimeout(init, 0); |
OLD | NEW |