Index: include.preload.js |
=================================================================== |
--- a/include.preload.js |
+++ b/include.preload.js |
@@ -43,16 +43,39 @@ function setElemhideCSSRules(selectors) |
} |
function sendRequests() |
{ |
// Make sure this is really an HTML page, as Chrome runs these scripts on just about everything |
if (!(document.documentElement instanceof HTMLElement)) |
return; |
+ chrome.extension.onMessage.addListener(function(request, sender, sendResponse) |
+ { |
+ switch (request.reqtype) |
+ { |
+ case "hide-element": |
+ if (request.documentUrl != document.URL) |
+ return; |
+ |
+ // We have little way of knowing which element was blocked - see |
+ // http://code.google.com/p/chromium/issues/detail?id=97392. Have to |
+ // look through all of them and try to find the right one. |
+ var remove = []; |
+ var elements = (request.type == "IMAGE" ? document.images : document.getElementsByTagName("iframe")); |
+ for (var i = 0; i < elements.length; i++) |
Thomas Greiner
2012/10/26 14:21:54
don't access elements.length on each iteration (cr
|
+ if (elements[i].src == request.url) |
+ remove.push(elements[i]); |
Thomas Greiner
2012/10/26 14:21:54
we could break after we found one element
Wladimir Palant
2012/10/26 14:34:23
I don't think we should, it isn't necessarily a si
|
+ |
+ for (var i = 0; i < remove.length; i++) |
Thomas Greiner
2012/10/26 14:21:54
not as important as with elements.length but still
|
+ if (remove[i].parentNode) |
+ remove[i].parentNode.removeChild(remove[i]); |
+ } |
+ }); |
+ |
chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameUrl: window.location.href}, function(response) |
{ |
setElemhideCSSRules(response.selectors); |
}); |
} |
// In Chrome 18 the document might not be initialized yet |
if (document.documentElement) |