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(); |