Explorar o código

added a simple way to remove backdrops

Gildas %!s(int64=7) %!d(string=hai) anos
pai
achega
939a7e3b0a
Modificáronse 1 ficheiros con 15 adicións e 7 borrados
  1. 15 7
      lib/single-file/doc-helper.js

+ 15 - 7
lib/single-file/doc-helper.js

@@ -31,6 +31,8 @@ this.docHelper = this.docHelper || (() => {
 	const INPUT_VALUE_ATTRIBUTE_NAME = "data-single-file-value";
 	const INPUT_VALUE_ATTRIBUTE_NAME = "data-single-file-value";
 	const SHEET_ATTRIBUTE_NAME = "data-single-file-sheet";
 	const SHEET_ATTRIBUTE_NAME = "data-single-file-sheet";
 	const IGNORED_REMOVED_TAG_NAMES = ["NOSCRIPT", "DISABLED-NOSCRIPT", "META", "LINK", "STYLE", "TITLE", "TEMPLATE", "SOURCE", "OBJECT"];
 	const IGNORED_REMOVED_TAG_NAMES = ["NOSCRIPT", "DISABLED-NOSCRIPT", "META", "LINK", "STYLE", "TITLE", "TEMPLATE", "SOURCE", "OBJECT"];
+	const MASK_TAGNAME = "singlefile-mask";
+	const BACKDROP_THRESHOLD = .95;
 
 
 	return {
 	return {
 		preProcessDoc,
 		preProcessDoc,
@@ -67,7 +69,7 @@ this.docHelper = this.docHelper || (() => {
 			if (win) {
 			if (win) {
 				markHiddenCandidates(win, doc.body, markerRemovedContent, markerRemovedCandidate, ignoredTags);
 				markHiddenCandidates(win, doc.body, markerRemovedContent, markerRemovedCandidate, ignoredTags);
 				markHiddenElements(win, doc.body, markerRemovedContent);
 				markHiddenElements(win, doc.body, markerRemovedContent);
-				markBackdropBackground(doc, win, markerRemovedCandidate);
+				markBackdropBackground(doc, win, markerRemovedContent);
 			}
 			}
 			doc.querySelectorAll(("[" + markerRemovedCandidate + "]")).forEach(element => element.removeAttribute(markerRemovedCandidate));
 			doc.querySelectorAll(("[" + markerRemovedCandidate + "]")).forEach(element => element.removeAttribute(markerRemovedCandidate));
 		}
 		}
@@ -90,17 +92,23 @@ this.docHelper = this.docHelper || (() => {
 		};
 		};
 	}
 	}
 
 
-	function markBackdropBackground(doc, win, markerRemovedCandidate) {
-		const threshold = .95;
-		const elements = doc.elementsFromPoint(win.innerWidth / 2, win.innerHeight / 2);
-		if (elements.length > 1) {
+	function markBackdropBackground(doc, win, markerRemovedContent) {
+		const threshold = BACKDROP_THRESHOLD;
+		let elements = getCandidateElements();
+		let fullScreen = true;
+		while (elements.length > 1 && fullScreen) {
+			elements = getCandidateElements();
 			const element = elements[0];
 			const element = elements[0];
 			const style = win.getComputedStyle(element);
 			const style = win.getComputedStyle(element);
-			const fullScreen = (element.clientWidth >= win.innerWidth * threshold) && (element.clientWidth >= win.innerWidth * threshold) && (style && style.getPropertyValue("z-index") >= 999);
+			fullScreen = (element.clientWidth >= win.innerWidth * threshold) && (element.clientHeight >= win.innerHeight * threshold) && (style && style.getPropertyValue("z-index") >= 999);
 			if (fullScreen) {
 			if (fullScreen) {
-				element.setAttribute(markerRemovedCandidate, "");
+				element.setAttribute(markerRemovedContent, "");
 			}
 			}
 		}
 		}
+
+		function getCandidateElements() {
+			return Array.from(doc.elementsFromPoint(win.innerWidth / 2, win.innerHeight / 2)).filter(element => element.tagName.toLowerCase() != MASK_TAGNAME && element.getAttribute(markerRemovedContent) == null);
+		}
 	}
 	}
 
 
 	function markHiddenCandidates(win, element, markerRemovedContent, markerRemovedCandidate, ignoredTags) {
 	function markHiddenCandidates(win, element, markerRemovedContent, markerRemovedCandidate, ignoredTags) {