Sfoglia il codice sorgente

remove styles of hidden elements (fix #289)

Former-commit-id: 0700b2c622553de03b8d3aef9a86868fde03f75d
Gildas 6 anni fa
parent
commit
9c4b3d7c47
1 ha cambiato i file con 8 aggiunte e 0 eliminazioni
  1. 8 0
      lib/single-file/modules/css-matched-rules.js

+ 8 - 0
lib/single-file/modules/css-matched-rules.js

@@ -27,6 +27,8 @@ this.singlefile.lib.modules.matchedRules = this.singlefile.lib.modules.matchedRu
 
 	const MEDIA_ALL = "all";
 	const IGNORED_PSEUDO_ELEMENTS = ["after", "before", "first-letter", "first-line", "placeholder", "selection"];
+	const SINGLE_FILE_HIDDEN_CLASS_NAME = "sf-hidden";
+	const DISPLAY_STYLE = "display";
 	const REGEXP_VENDOR_IDENTIFIER = /-(ms|webkit|moz|o)-/;
 	const DEBUG = false;
 
@@ -140,6 +142,12 @@ this.singlefile.lib.modules.matchedRules = this.singlefile.lib.modules.matchedRu
 		if (!matchedElements) {
 			try {
 				matchedElements = doc.querySelectorAll(selectorText);
+				if (selectorText != "." + SINGLE_FILE_HIDDEN_CLASS_NAME) {
+					matchedElements = Array.from(doc.querySelectorAll(selectorText)).filter(matchedElement =>
+						!matchedElement.classList.contains(SINGLE_FILE_HIDDEN_CLASS_NAME) &&
+						(matchedElement.style.getPropertyValue(DISPLAY_STYLE) != "none" || matchedElement.style.getPropertyPriority("display") != "important")
+					);
+				}
 			} catch (error) {
 				// ignored				
 			}