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

Unified Diff: include.preload.js

Issue 6393086494113792: Issue 154 - Added devtools panel showing blocked and blockable items (Closed)
Patch Set: Rebased Created March 3, 2015, 3:16 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 | « chrome/ext/devtools.js ('k') | lib/devtools.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
@@ -94,6 +94,51 @@
return contentDocument.location.protocol == "about:";
}
+function traceHiddenElements(document, selectors)
+{
+ function check(element)
+ {
+ var matchedSelectors = [];
+
+ for (var i = 0; i < selectors.length; i++)
+ {
+ var selector = selectors[i];
+ var elements = document.querySelectorAll(selector);
+
+ for (var j = 0; j < elements.length; j++)
+ {
+ if (getComputedStyle(elements[j]).display == "none")
+ {
+ matchedSelectors.push(selector);
+ break;
+ }
+ }
+ }
+
+ if (matchedSelectors.length > 0)
+ ext.backgroundPage.sendMessage({type: "trace-elemhide", selectors: matchedSelectors});
+ }
+
+ function trace()
+ {
+ check();
+
+ new MutationObserver(check).observe(
+ document,
+ {
+ childList: true,
+ attributes: true,
+ subtree: true
+ }
+ );
+ }
+
+ if (document.readyState == "loading")
+ document.addEventListener("DOMContentLoaded", trace);
+ else
+ trace();
+}
+
function reinjectRulesWhenRemoved(document, style)
{
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
@@ -193,14 +238,15 @@
}
// Sets the currently used CSS rules for elemhide filters
- var setElemhideCSSRules = function(selectors)
+ var setElemhideCSSRules = function(response)
{
- if (selectors.length == 0)
+ if (response.selectors.length == 0)
return;
var style = document.createElement("style");
style.setAttribute("type", "text/css");
+ var selectors = response.selectors;
if (shadow)
{
shadow.appendChild(style);
@@ -231,6 +277,9 @@
var selector = selectors.splice(0, SELECTOR_GROUP_SIZE).join(", ");
style.sheet.insertRule(selector + " { display: none !important; }", i);
}
+
+ if (response.trace)
+ traceHiddenElements(document, response.selectors);
};
setRules();
« no previous file with comments | « chrome/ext/devtools.js ('k') | lib/devtools.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld