Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: include.preload.js

Issue 8684066: Fixed "Hide placeholders of blocked elements" feature (Closed)
Patch Set: Created Oct. 26, 2012, 1:56 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld