Index: include.preload.js |
=================================================================== |
--- a/include.preload.js |
+++ b/include.preload.js |
@@ -104,6 +104,51 @@ |
return a.href; |
} |
+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; |
@@ -203,14 +248,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); |
@@ -241,6 +287,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(); |