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: Created Jan. 4, 2015, 9:48 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
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -152,6 +152,53 @@
observer.observe(style.parentNode, {childList: true});
}
+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();
+
+ var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
+ if (MutationObserver)
+ {
+ new MutationObserver(check).observe(document,
+ {
+ childList: true,
+ attributes: true,
+ subtree: true
+ });
+ }
+ }
+
+ if (document.readyState == "loading")
+ document.addEventListener("DOMContentLoaded", trace);
+ else
+ trace();
+}
+
function init(document)
{
// use Shadow DOM if available to don't mess with web pages that
@@ -166,11 +213,12 @@
}
// 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 selectors = response.selectors.slice(0);
var style = document.createElement("style");
style.setAttribute("type", "text/css");
@@ -206,6 +254,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();

Powered by Google App Engine
This is Rietveld