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, 2:33 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, l = elements.length; i < l; i++)
+ if (elements[i].src == request.url)
+ remove.push(elements[i]);
+
+ for (var i = 0, l = remove.length; i < l; i++)
+ 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