|
|
@@ -64,7 +64,7 @@ this.docHelper = this.docHelper || (() => {
|
|
|
ignoredTags = ignoredTags.concat("SCRIPT");
|
|
|
}
|
|
|
if (win) {
|
|
|
- markHiddenCandidates(win, doc.body, markerRemovedContent, new Set(), ignoredTags, new Map());
|
|
|
+ markHiddenCandidates(win, doc.body, false, markerRemovedContent, new Set(), ignoredTags);
|
|
|
markHiddenElements(win, doc.body, markerRemovedContent);
|
|
|
markBackdropBackground(doc, win, markerRemovedContent);
|
|
|
}
|
|
|
@@ -107,23 +107,21 @@ this.docHelper = this.docHelper || (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function markHiddenCandidates(win, element, markerRemovedContent, removedCandidates, ignoredTags, cacheElementsHidden) {
|
|
|
- const elements = Array.from(element.childNodes).filter(node => node.nodeType == win.Node.ELEMENT_NODE);
|
|
|
- elements.forEach(element => markHiddenCandidates(win, element, markerRemovedContent, removedCandidates, ignoredTags, cacheElementsHidden));
|
|
|
- if (elements.length) {
|
|
|
- const hiddenCandidate = !elements.find(element => !removedCandidates.has(element));
|
|
|
- if (hiddenCandidate) {
|
|
|
- if (hiddenElement(win, element, ignoredTags, cacheElementsHidden) && element instanceof win.HTMLElement) {
|
|
|
+ function markHiddenCandidates(win, element, elementHidden, markerRemovedContent, removedCandidates, ignoredTags) {
|
|
|
+ const elements = Array.from(element.childNodes).filter(node => node instanceof win.HTMLElement);
|
|
|
+ elements.forEach(element => markHiddenCandidates(win, element, elementHidden || testHiddenElement(win, element), markerRemovedContent, removedCandidates, ignoredTags));
|
|
|
+ if (elementHidden && !ignoredTags.includes(element.tagName)) {
|
|
|
+ if (elements.length) {
|
|
|
+ const hiddenCandidate = !elements.find(element => !removedCandidates.has(element));
|
|
|
+ if (hiddenCandidate) {
|
|
|
removedCandidates.add(element);
|
|
|
elements.forEach(element => {
|
|
|
- if (element instanceof win.HTMLElement) {
|
|
|
- element.setAttribute(markerRemovedContent, "");
|
|
|
- }
|
|
|
+ element.setAttribute(markerRemovedContent, "");
|
|
|
});
|
|
|
}
|
|
|
+ } else {
|
|
|
+ removedCandidates.add(element);
|
|
|
}
|
|
|
- } else if (hiddenElement(win, element, ignoredTags, cacheElementsHidden)) {
|
|
|
- removedCandidates.add(element);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -135,43 +133,19 @@ this.docHelper = this.docHelper || (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function hiddenElement(win, element, ignoredTags, cacheElementsHidden) {
|
|
|
- const hidden = testHiddenElement(win, element, ignoredTags, cacheElementsHidden);
|
|
|
+ function testHiddenElement(win, element) {
|
|
|
+ let hidden = element.hidden;
|
|
|
if (!hidden) {
|
|
|
- let parentElement = element.parentElement;
|
|
|
- if (parentElement) {
|
|
|
- let parentElementHidden = testHiddenElement(win, parentElement, ignoredTags, cacheElementsHidden);
|
|
|
- while (parentElement && !parentElementHidden) {
|
|
|
- parentElement = parentElement.parentElement;
|
|
|
- if (parentElement) {
|
|
|
- parentElementHidden = testHiddenElement(win, parentElement, ignoredTags, cacheElementsHidden);
|
|
|
- }
|
|
|
- }
|
|
|
- return parentElementHidden;
|
|
|
- }
|
|
|
- }
|
|
|
- return hidden;
|
|
|
- }
|
|
|
-
|
|
|
- function testHiddenElement(win, element, ignoredTags, cacheElementsHidden) {
|
|
|
- let hidden = cacheElementsHidden.get(element);
|
|
|
- if (hidden === undefined) {
|
|
|
- if (!ignoredTags.includes(element.tagName)) {
|
|
|
- hidden = element.hidden;
|
|
|
- if (!hidden) {
|
|
|
- const style = win.getComputedStyle(element);
|
|
|
- if (style) {
|
|
|
- hidden = style.display == "none";
|
|
|
- if (!hidden && (style.opacity == "0" || style.visibility == "hidden")) {
|
|
|
- const boundingRect = element.getBoundingClientRect();
|
|
|
- hidden = !boundingRect.width && !boundingRect.height;
|
|
|
- }
|
|
|
- }
|
|
|
+ const style = win.getComputedStyle(element);
|
|
|
+ if (style) {
|
|
|
+ hidden = style.display == "none";
|
|
|
+ if (!hidden && (style.opacity == "0" || style.visibility == "hidden")) {
|
|
|
+ const boundingRect = element.getBoundingClientRect();
|
|
|
+ hidden = !boundingRect.width && !boundingRect.height;
|
|
|
}
|
|
|
- cacheElementsHidden.set(element, hidden);
|
|
|
}
|
|
|
- hidden = Boolean(hidden);
|
|
|
}
|
|
|
+ hidden = Boolean(hidden);
|
|
|
return hidden;
|
|
|
}
|
|
|
|